当前位置:网站首页>2022蓝桥杯国赛B组-2022-(01背包求方案数)
2022蓝桥杯国赛B组-2022-(01背包求方案数)
2022-06-30 15:44:00 【可爱美少女】
题意:
就是让你把2022拆分成10个不相同的正整数之和,一共有多少种方法。
思考:
害,感觉期末一段实际不训练确实脑子很傻逼。比赛的时候想这像那。实际上这就是2022种物品,然后每种物品只能用一次,然后用10个物品组成2022有多少种方案书。定义dp[i][j]代表用了i个物品,此时综合为j的方案书。明显dp[0][0] = 1。然后第一维枚举物品,第二维倒序枚举用了多少物品,倒叙是因为要保证当前枚举的第i个物品,只用一次,因为转移只能从小的转移,但是倒叙枚举的时候,小的还没有被更新,也就是小的还没有用这个i物品,所以保证了i这个物品只用了一次。然后第三维枚举总和,这个总和倒叙正序无所谓了,因为转移的时候都是从j-1转移的,也就是从用了j-1个物品来转移的,所以这里不会出现i的重复使用。
代码:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define db double
#define int long long
#define PII pair<int,int >
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7,inf = 1e18;
const int N = 1e5+10,M = 2010;
int T,n,m,k;
int va[N];
int dp[15][2500];
signed main()
{
IOS;
dp[0][0] = 1;
for(int i=1;i<=2022;i++)
{
for(int j=10;j>=1;j--)
{
for(int k=i;k<=2022;k++)
dp[j][k] += dp[j-1][k-i];
}
}
cout<<dp[10][2022];
return 0;
}
总结:
多多思考,不要思想傻逼性问题,无论何时都要坚持每天看一点代码。
边栏推荐
- Interesting research on mouse pointer interaction
- 【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!
- 【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
- 中航无人机科创板上市:市值385亿 拳头产品是翼龙无人机
- 如何得到股票开户的优惠活动?在线开户安全么?
- Policy Center-Permissions and APIs that Access Sensitive Information
- Unsupported major.minor version 52.0
- Asp. NETCORE uses cache and AOP to prevent repeated commit
- I 用c I 实现“栈”
- 深入分析GadgetInspector核心代码
猜你喜欢

ArcMap operation series: 80 plane to latitude and longitude 84

中国传奇教授李泽湘,正在批量制造独角兽

中航无人机科创板上市:市值385亿 拳头产品是翼龙无人机

婴儿认知学习所带来的启发,也许是下一代无监督机器学习的关键

Lecun points out the direction of next generation AI: autonomous machine intelligence

分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)

Distributed machine learning: model average Ma and elastic average easgd (pyspark)

【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)

Simulation of two-color ball system to judge the winning situation

牛客网:有多少个不同的二叉搜索树
随机推荐
【Verilog基础】十进制负数的八进制、十六进制表示
招标公告:天津市住房公积金管理中心数据库一体机及数据库软件项目(预算645万)
[附下载]渗透测试神器Nessus安装及使用
备战数学建模36-时间序列模型2
Simulate user login function
思源笔记:能否提供页面内折叠所有标题的快捷键?
In depth analysis of the core code of the gadgetinspector
flinkcdc如果监控的数据库为mongo就必须是集群版吗
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
Log4j2 进阶使用
牛客网:乘积为正数的最长连续子数组
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
Simulation of two-color ball system to judge the winning situation
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
超 Nice 的表格响应式布局小技巧
register_chrdev和cdev_init cdev_add用法区别
Mysql代理中间件Atlas安装和配置
Policy Center > Device and Network Abuse
halcon知识:区域专题【07】
详解Go语言中for循环,break和continue的使用