当前位置:网站首页>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;
}
总结:
多多思考,不要思想傻逼性问题,无论何时都要坚持每天看一点代码。
边栏推荐
- The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning
- Swagger's asp Net core web API help page
- Warning: [antd: Menu] `children` will be removed in next major version. Please use `items` instead.
- 牛客网:有多少个不同的二叉搜索树
- Log4j2 advanced use
- 中国传奇教授李泽湘,正在批量制造独角兽
- Interview experience of service end test engineer
- Distributed machine learning: model average Ma and elastic average easgd (pyspark)
- Cesium-1.72 learning (deploy offline resources)
- Dart: string replace related methods to solve replacement characters
猜你喜欢
The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
How cloudxr promotes the future development of XR
'&lt;', Hexadecimal value 0x3c, is an invalid problem solving
ArcMap operation series: 80 plane to latitude and longitude 84
容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态
Simulate user login function
MC Instruction Decoder
互联网研发效能之去哪儿网(Qunar)核心领域DevOps落地实践
Google play index table
【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!
随机推荐
【牛客网刷题系列 之 Verilog快速入门】~ 位拆分与运算
Reptile (1) - Introduction to basic reptile theory
大学生研究生毕业找工作,该选择哪个方向?
容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态
Generating verification code with sring
Arcmap操作系列:80平面转经纬度84
Create statement for Oracle export view
MicroBlaze serial port learning · 2
Cesium-1.72 learning (deploy offline resources)
flink sql cdc 同步sqlserver 报错什么原因啊
Cloud XR, how to help industrial upgrading
【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
Cesium-1.72 learning (add points, lines, cubes, etc.)
CVPR 2022丨特斯联AI提出:基于图采样深度度量学习的可泛化行人重识别
Policy Center > Deceptive Behavior
Solution for IIS failing to load font files (*.woff, *.svg)
How to connect the Internet Reading Notes - Summary
MySQL master-slave configuration
Which direction should college students choose to find jobs after graduation?
'&lt;', Hexadecimal value 0x3c, is an invalid problem solving