标签:style http io ar color os sp for on
4 13 1 2 4 7
YES 2 4 7
#include<stdio.h> #include<string.h> int cur,sum,n,k,ok,left; int visit[22],a[22]; void dfs(int pos) { int i; if(left==k) { printf("YES\n"); for(i=1;i<=n;++i) if(visit[i]) { printf("%d",a[i]); break; } for(i=i+1;i<=n;++i) if(visit[i]) printf(" %d",a[i]); printf("\n"); ok=1; return ; } if(left>k) { return ; } for(i=pos;i<=n;++i) { if(!visit[i]) { visit[i]=1; left+=a[i]; dfs(i+1); visit[i]=0; left-=a[i]; } if(ok) return ; } } int main() { int i; while(~scanf("%d%d",&n,&k)) { ok=0; memset(visit,0,sizeof(visit)); for(i=1;i<=n;++i) scanf("%d",&a[i]); dfs(0); if(!ok) printf("NO\n"); } return 0; }
标签:style http io ar color os sp for on
原文地址:http://blog.csdn.net/qq_18062811/article/details/41596489