标签:style blog io sp for on 2014 log bs
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[28]; long long a1[20005],a2[20005]; int s,e; int T; int t1,t2; int n,k; void dfs(int x,long long v) { if(x==e) { if(e==n) a1[t1++]=v; else if(e==n/2) a2[t2++]=v; return ; } for(int i=0; i<=2; i++) dfs(x+1,v+i*a[x]); } int main() { while(scanf("%d",&T)==1) { int cases=1; while(T--) { memset(a1,0,sizeof(a1)); memset(a2,0,sizeof(a2)); scanf("%d%d",&n,&k); for(int i=0; i<n; i++) scanf("%d",&a[i]); t1=t2=0; e=n/2; dfs(0,0); e=n; dfs(n/2,0); sort(a2,a2+t2); int j,l,mid,r; for( j=0; j<t1; j++) { long long h=k-a1[j]; l=0; r=t2-1; while(l<=r) { mid =(l+r)>>1; if(a2[mid]==h)break; if(a2[mid]>h) r=mid-1; else l=mid+1; } if(l<=r) break; } if(j<t1) printf("Case %d: Yes\n",cases++); else printf("Case %d: No\n",cases++); } } }
lightoj 1235 Coin Change (IV)(折半枚举)
标签:style blog io sp for on 2014 log bs
原文地址:http://blog.csdn.net/u013076044/article/details/41522669