还是日语,解释题目:
1到10编号的10个球从容器A掉下,可掉入筒B或筒C中
要求:筒B和筒C中球的号码由大到小
Sample Input
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
Output for the Sample Input
YES
NO
我们只要关注筒中号码最大的那个就行了
#include<iostream>
#include<cstring>
using namespace std;
int a[12],bo;
void dfs(int b,int c,int i)//b中最大的号码,c中最大的号码
{
if(bo) return;
if(i>10)
{
bo=1;
return ;
}
if(b<a[i]) dfs(a[i],c,i+1);
if(c<a[i]) dfs(b,a[i],i+1);
}
int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=1;i<=10;i++)
cin>>a[i];
bo=0;
(dfs(0,0,1));
if(bo) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}