当前位置:网站首页>计数类DP AcWing 900. 整数划分
计数类DP AcWing 900. 整数划分
2022-07-02 09:43:00 【T_Y_F666】
计数类DP AcWing 900. 整数划分
原题链接
算法标签
动态规划 计数类DP
思路




代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f, mod = 1e9+7;
int n;
int f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
// f[1] = 1 且 f[1] = f[1] + f[0],所以 f[0] = 1
// 也可理解只从前 0 个数选且和为 0 的方案数是 1,因为不选可以满足和为 0,也是一种方案
f[0]=1;
// 对于第i个数
rep(i, 1, n+1){
// 剩余容量
rep(j, i, n+1){
f[j]=(f[j]+f[j-i])%mod;
}
}
printf("%lld", f[n]);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Go学习笔记—基于Go的进程间通信
- Fluent fluent library encapsulation
- 防抖 节流
- WSL 2 will not be installed yet? It's enough to read this article
- How to write a pleasing English mathematical paper
- mysql表的增删改查(进阶)
- Post request body content cannot be retrieved repeatedly
- Leetcode922 sort array by parity II
- 上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
- 趣味 面试题
猜你喜欢

This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry

趣味 面试题

Record the range of data that MySQL update will lock
![[ybtoj advanced training guidance] judgment overflow [error]](/img/be/bbe357ac2f2a8839afc5af47db88d0.jpg)
[ybtoj advanced training guidance] judgment overflow [error]

High performance erasure code coding

The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

Embedded Software Engineer career planning

Go学习笔记—多线程

Test shift left and right
随机推荐
【工控老马】西门子PLC Siemens PLC TCP协议详解
Lombok common annotations
From scratch, develop a web office suite (3): mouse events
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
The blink code based on Arduino and esp8266 runs successfully (including error analysis)
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
Post request body content cannot be retrieved repeatedly
Leetcode - Sword finger offer 51 Reverse pairs in an array
Go学习笔记—基于Go的进程间通信
arcgis js 4. Add pictures to x map
Leetcode14 longest public prefix
AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
Mysql database foundation
kubeadm join时出现错误:[ERROR Port-10250]: Port 10250 is in use [ERROR FileAvailable--etc-kubernetes-pki
Jenkins user rights management
单指令多数据SIMD的SSE/AVX指令集和API
寻找二叉树中任意两个数的公共祖先
Take you ten days to easily finish the finale of go micro services (distributed transactions)