5 solutions
-
0
Guest MOD
-
1
#include <bits/stdc++.h> //#include <inout.h> #define int long long #define endl "\n" using namespace std; map<int,int>mp; int n,m,dp[1000005],d[1000005],a[30]; signed main() { int T;cin>>T; while(T--){ cin>>n>>m; for(int i=1;i<=n;i++)cin>>a[i]; mp.clear(); for(int i=1;i<=m;i++)cin>>d[i],mp[d[i]]=1; memset(dp,0,sizeof(dp)); dp[0]=1; for(int s=1;s<(1<<n);s++){ int tim=0; for(int i=0;i<n;i++){ if((1<<i)&s){ dp[s]|=dp[s-(1<<i)]; tim+=a[i+1]; } } if(mp[tim])dp[s]=0; } puts(dp[(1<<n)-1]?"YES":"NO"); } return 0; }
Information
- ID
- 305
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 140
- Accepted
- 27
- Uploaded By