可以套完全背包。
每次累加起来就好了。
#include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream> #include<list> #include<set> #include<vector> #include<cmath> #define INF 0x7fffffff #define eps 1e-8 #define LL long long #define PI 3.141592654 #define CLR(a,b) memset(a,b,sizeof(a)) #define FOR(i,a,n) for(int i= a;i< n ;i++) #define FOR0(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define mp make_pair #define ft first #define sd second #define sf scanf #define pf printf #define acfun std::ios::sync_with_stdio(false) #define SIZE 120+1 using namespace std; int dp[SIZE]; int main() { CLR(dp,0); dp[0]=1; FOR(i,1,SIZE) FOR(j,i,SIZE) dp[j]+=dp[j-i]; int n; while(~sf("%d",&n)) pf("%d\n",dp[n]); }
时间: 2024-10-22 17:08:16