Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int mod = 1000000007;
- const int N = 500005;
- const int LG = 21;
- int n,h;
- int arr[50];
- int brr[50];
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- for (int tt = 1;tt<=t;tt++) {
- cout<<"Case #"<<tt<<": ";
- int n,h;
- cin >> n >> h;
- int count =0;
- int dp[1ll<<n];
- int val1[1ll<<n];
- int val2[1ll<<n];
- memset(dp,0,sizeof(dp));
- memset(val1,0,sizeof(val1));
- memset(val2,0,sizeof(val2));
- for(int i=0;i<n;i++){
- cin >> arr[i];
- }
- for(int i=0;i<n;i++){
- cin >> brr[i];
- }
- for(int i=0;i<(1ll<<n);i++){
- for(int j=n-1;j>=0;j--){
- if(i&(1ll<<j))
- val1[i] += brr[j];
- else
- val2[i] += brr[j];
- }
- }
- for(int i=0;i<(1ll<<n);i++){
- if(val1[i] >= h)
- dp[i]++;
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<(1ll<<n);j++){
- if(j & (1ll<<i)){
- if(val1[j ^ (1ll<<i)] + val2[j] >= h)
- dp[j]++;
- }
- }
- }
- for(int i=0;i<(1ll<<n);i++){
- int ha=0;
- for(int j=n-1;j>=0;j--){
- if(i&(1ll<<j))
- ha += arr[j];
- }
- if(ha >= h )
- count += dp[i];
- }
- cout<<count<<"\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment