이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n,m,a[25],B[25],dp[2000006][25],i,j,k,s;
vector<int>V[25];
bool go(int b,int i){
if(i==n) {
return 1;
}
bool F=0;
if(dp[b][i]!=-1) return dp[b][i];
for(int j=0;j<V[i].size();j++){
if((b&V[i][j])==V[i][j]) {
if(i+1==n) return dp[b][i]=1;
F=max(F,go(b^V[i][j],i+1));
}
}
if (!F) {
dp[b][i]=0; return 0;
}
return dp[b][i]=1;
}
int main(){
cin>>n>>m;
for(k=0;k<n;k++){
cin>>a[k];
}
for(k=0;k<m;k++)
cin>>B[k];
for(k=0;k<n;k++){
s=0;
for(i=0;i< (1<<m); i++){
s=0; dp[i][k]=-1;
for(int j=0;j<=m;j++){
int b=1<<j;
if(b&i)s+=B[j];
}
if(s==a[k]) V[k].push_back(i);
}
}int b=1<<(m);
if(go(b-1,0))cout<<"YES";
else cout<<"NO";
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool go(int, int)':
bank.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int j=0;j<V[i].size();j++){
| ~^~~~~~~~~~~~
bank.cpp:13:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
13 | if(i+1==n) return dp[b][i]=1;
| ~~~~~~~~^~
bank.cpp:20:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
20 | return dp[b][i]=1;
| ~~~~~~~~^~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |