标签:style blog color os art for
4 1 2 4 7 13 4 1 2 4 7 15
Of course,I can! Sorry,I can‘t!
#include <stdio.h> int e[25]; int imt; int num; int dfs(int step,int count)//深度搜索 这里还用到了动态规划的思想 01背包问题 { if(step==num) return count==imt; if(dfs(step+1,count)) return 1; if(dfs(step+1,count+e[step])) return 1; return 0; } int main() { int i,j,k; while(scanf("%d",&num)!=EOF) { for(i=0;i<num;i++) { scanf("%d",e+i); } scanf("%d",&imt); if(dfs(0,0)) printf("Of course,I can!\n"); else printf("Sorry,I can‘t!\n"); } return 0; }
刚开始写的时候一直超时,很郁闷,搜索了下,发现用深搜加上动态规划的思想便可以解决~,很棒的一种方法~
nyoj 927 The partial sum problem,布布扣,bubuko.com
nyoj 927 The partial sum problem
标签:style blog color os art for
原文地址:http://www.cnblogs.com/ltwy/p/3841278.html