标签:
10 87 2 3 4 5 7 9 10 11 12 13 10 38 2 3 4 5 7 9 10 11 12 13
No Yes
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<vector> #include<queue> #include<stack> #include<algorithm> #define LL long long using namespace std; const int MAXN=2e6+7; int n,H; int a[MAXN],sum[MAXN]; int main() { int n,H; while(scanf("%d %d",&n,&H)!=EOF) { for(int i=0;i<n;i++) scanf("%d",&a[i]); int c=0,k=n>>1; for(int i=0;i<(1<<k);i++) { LL s=0; for(int j=0;j<k;j++) { if((1<<j)&i) s+= a[j]; } if(s<=H) sum[c++]=s; } sort(sum,sum+c); int res=n-k; bool ok=false; for (int i=0;i<(1<<res);i++) { LL s=0; for(int j=0;j<res;j++) { if ((1<<j)&i) s+=a[k+j]; } if (s>H) continue; if (sum[lower_bound(sum,sum+c,H-s)-sum]==H-s) { ok=true; break; } } puts(ok?"Yes":"No"); } return 0; }
ACDream 1726 A Math game (折半查找)
标签:
原文地址:http://www.cnblogs.com/clliff/p/4490599.html