当前位置:网站首页>[dynamic planning] - counting DP
[dynamic planning] - counting DP
2022-07-18 05:28:00 【Xuanche_】

AcWing 900. Integer partition
sample input :
5sample output :
7
You can think of the problem as Capacity is n The backpack , The volume of the objects in the backpack is 1 ~ n , Each item can be used unlimited times
It is equivalent to a Complete knapsack problem


It can be seen from the following figure :

![f[i][j] = f[i - 1][j] + f[i][j - i]](http://img.inotgo.com/imagesLocal/202207/18/202207151533333456_3.gif)
Further optimization is available :
![f[j] = f[j] + f[j - i]](http://img.inotgo.com/imagesLocal/202207/18/202207151533333456_8.gif)
#include <iostream> #include <algorithm> using namespace std; const int N = 1010, M = 1e9 + 7; int n; int f[N]; int main() { cin >> n; f[0] = 1; for(int i = 1; i <= n; i ++ ) for(int j = i; j <= n; j ++ ) f[j] = (f[j] + f[j - i]) % M; cout << f[n] << endl; return 0; }

![f[i,j]=f[i-1,j-1] + f[i - j,j]](http://img.inotgo.com/imagesLocal/202207/18/202207151533333456_10.gif)
![ans=f[n,1]+[n,2]+\cdots +f[n,n]](http://img.inotgo.com/imagesLocal/202207/18/202207151533333456_6.gif)
#include <iostream> #include <algorithm> using namespace std; const int N = 1010, M = 1e9 + 7; int n; int f[N][N]; int main() { cin >> n; f[0][0] = 1; for(int i = 1; i <= n; i ++ ) for(int j = 1; j <= i; j ++ ) f[i][j] = (f[i - 1][j - 1] + f[i - j][j]) % M; int res = 0; for(int i = 1; i <= n; i ++ ) res = (res + f[n][i]) % M; cout << res << endl; return 0; }
边栏推荐
- Information system project manager 10 days before the exam limit sprint + answer (10): summary of comprehensive knowledge
- 【综合笔试题】难度 2/5,递归运用及前缀和优化
- 阿里云E-MapReduce 极客大赛开放报名 数十万奖金等你挑战
- virtual box挂载共享文件夹
- 【用户文章】P4合并实践指南之实例拆解Resolve
- Considérations relatives à la mise en œuvre du modèle d'influence de la campagne dans Salesforce
- Interview question set
- Assist developers to comprehensively interpret APIs IX test cases
- Use Tibco rendezvous to send Hello world to realize monitoring and sending
- Interpolation method to calculate the value between two points
猜你喜欢

Huawei image xmage: seek all the images in the world, and finally see the Bodhi Heart

JMM内存模型

STM32F103 serial port +dma interrupt to realize data sending and receiving

Use Tibco rendezvous to send Hello world to realize monitoring and sending

在Salesforce中基于SAML 2.0搭建SSO并启用JIT User Provisioning(SF Orgs间 / SF Org与Experience Cloud间 / 其他IdP)

Information system project managers must recite the core examination points (IV) the relationship between UML classes

Doxygen的安装与使用及注释语法

Live delivery system source code
![[comprehensive pen test] difficulty 2/5, recursive application, prefix and optimization](/img/eb/fad095522129d13be7675a50e77af7.png)
[comprehensive pen test] difficulty 2/5, recursive application, prefix and optimization

Information system project manager core examination site (IX) organizational structure type
随机推荐
Installation and use of Doxygen and annotation syntax
Introduction to STM32 IO port mode
ComboBoxEdit设置选项值(单选 多选)
Salesforce邮件发进垃圾邮箱或未收到SF邮件处理方式 (DKIM - New CNAME Version)
游戏有什么用?| 游戏应用价值研究案例征集
Volatile low configuration syn, realizing visibility and order
Salesforce中实施Campaign Influence模型注意事项
C#利用浏览按钮获得文件路径和文件夹路径
CFA考试报名须知
Salesforce File Share and Security
Crmeb Pro v1.4 makes the user experience more brilliant!
Salesforce项目中使用ETL工具做数据迁移
sx126x 与 sx127x 的区别
堪比猎头简历整理技巧 如何快速整理简历
JMM memory model
volatile低配版syn,实现可见性和有序性
Core examination points for information system project managers (VII) software architecture style
摄提格,是外来词音译,还是有特定含义?
Sx1268 chip Manual Chapter 13 translation
Alibaba cloud e-mapreduce geek competition is open for registration. Hundreds of thousands of bonuses are waiting for you to challenge
