当前位置:网站首页>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;
}
总结:
多多思考,不要思想傻逼性问题,无论何时都要坚持每天看一点代码。
边栏推荐
- In depth analysis of the core code of the gadgetinspector
- 【算法篇】四种链表总结完毕,顺手刷了两道面试题
- Policy Center > Misrepresentation
- There are so many kinds of coupons. First distinguish them clearly and then collect the wool!
- [CVE-2019-0193] - Apache Solr DataImport 远程命令执行分析
- Simulation of two-color ball system to judge the winning situation
- CloudXR如何推动XR的未来发展
- Phone number shielding function
- Log4j2 advanced use
- 云技能提升好伙伴,亚马逊云师兄今天正式营业
猜你喜欢

24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);

【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!

备战数学建模36-时间序列模型2

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

The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer

Under the pressure of technology, you can quickly get started with eth smart contract development, which will take you into the ETH world

云化XR,如何助力产业升级

Policy Center > Deceptive Behavior

备战数学建模35-时间序列预测模型

LeCun指明下一代AI方向:自主机器智能
随机推荐
几百行代码实现一个 JSON 解析器
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
topic: Privacy, Deception and Device Abuse
云和恩墨中标天津滨海农村商业银行2022-2023年度Oracle维保项目
Bidding announcement: Taizhou Unicom Oracle all in one machine and database maintenance service project in 2022
思源笔记:能否提供页面内折叠所有标题的快捷键?
Types of waveguides
智慧风电:数字孪生 3D 风机智能设备运维
Create statement for Oracle export view
附加:(还没写,别看~~~)WebMvcConfigurer接口;
CVPR 2022丨特斯联AI提出:基于图采样深度度量学习的可泛化行人重识别
Under the pressure of technology, you can quickly get started with eth smart contract development, which will take you into the ETH world
Solution for IIS failing to load font files (*.woff, *.svg)
360数科、蚂蚁集团等入选中国信通院“业务安全推进计划”成员单位
【Verilog基础】十进制负数的八进制、十六进制表示
What are the reasons for the errors reported by the Flink SQL CDC synchronization sqlserver
Bidding announcement: remote disaster recovery project of Shenzhen Finance Bureau database
Explain in detail the use of for loop, break and continue in go language
大学生研究生毕业找工作,该选择哪个方向?
Unsupported major. minor version 52.0