#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[9],b[9],s,n,dp[6][6][6][6][6][6][6];
void check(int x[7])
{
for(int i=0;i<n;i++)
{
if(x[i]==b[i])continue;
else return;
}
cout<<"YES";
exit(0);
}
void bt(int x[7],int sm)
{
if(sm<s)return;
if(dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]])return;
//for(int i=0;i<n;i++)cout<<x[i]<<" ";cout<<"\n";
if(sm==s)
{
check(x);
return;
}
for(int i=0;i<n;i++)
{
if(x[i]<=1)continue;
x[i]-=2;
x[(i+1)%n]++;
bt(x,sm-1);
x[(i+1)%n]--;
x[i]+=2;
}
dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]]=1;
return;
}
int sm;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
sm+=a[i];
s+=b[i];
}
bt(a,sm);
cout<<"NO";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |