#include<map> #include<stdio.h> #include<iostream> using namespace std; long long box[50]; long long pos[50]; int main() { long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) { cin >> box[i]; } long long cnt = n / 2; map<long long, long long>a; for (long long i = 0; i < (1ll << cnt); i++) { long long ans = 0; for (long long j = 0; j < cnt; j++) { if (i & (1ll << j)) { ans += box[j]; } } a[ans] = i; } cnt = n - cnt; for (long long i = 0; i < (1ll << cnt); i++) { long long ans = 0; for (long long j = 0; j < cnt; j++) { if (i & (1ll << j)) { ans += box[n - cnt + j]; pos[j] = 1; } else pos[j] = 0; } if (a[m - ans]) { for (long long j = 0; j < cnt; j++) { if (a[m-ans] & (1ll << j)) { cout << "1"; } else { cout << "0"; } } break; } } for (long long i = 0; i < cnt; i++) { cout << pos[i]; } return 0; }
标签:折半,box,cin,long,50,查找,include From: https://www.cnblogs.com/BlueTeas/p/16759818.html