标签:div scan 时间 strong ble printf desc int panel
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4478 Accepted Submission(s): 3480
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int cost[10],num[10],dp[45],n; void zero_one(int cost,int num) { for(int j=n;j>=cost;j--) for(int k=1;k<=num&&j-k*cost>=0;k++) dp[j]+=dp[j-cost*k]; } int main() { int t,k; scanf("%d",&t); while(t--) { memset(dp,0,sizeof(dp)); dp[0]=1; scanf("%d%d",&n,&k); for(int i=0;i<k;i++) { scanf("%d%d",&cost[i],&num[i]); if(cost[i]*num[i]>n) num[i]=n/cost[i]; //dp[cost[i]]=1; } for(int i=0;i<k;i++) { zero_one(cost[i],num[i]); } printf("%d\n",dp[n]); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int cost[10],num[10],res,n,k; void dfs(int index,int sum) { if(index>k||sum>n) return; if(index==k&&sum!=n) return; if(sum==n) { res++; return; } for(int i=0;i<=num[index];i++) { dfs(index+1,sum+i*cost[index]); } } int main() { int t; scanf("%d",&t); while(t--) { res=0; scanf("%d%d",&n,&k); for(int i=0;i<k;i++) scanf("%d%d",&cost[i],&num[i]); dfs(0,0); printf("%d\n",res); } return 0; }
标签:div scan 时间 strong ble printf desc int panel
原文地址:http://www.cnblogs.com/jasonlixuetao/p/6390760.html