AOJ 0033 DFS
来源:互联网 发布:挣钱的软件 编辑:程序博客网 时间:2024/05/01 10:36
题意:有一个数列,1-10,10个元素乱排,问是否可以将数列按顺序抽出元素组成新数列,使得新数列是递增的而且原数列剩下的数字也是递增的
题解:
dfs,记录步数和当前两个新数列的末尾,如果可以放,就下一轮dfs,完全是模拟了题目的一个图形
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<queue>#define pr(x) cout<<#x<<" "<<x;#define pl(x) cout<<#x<<" "<<x<<endl;#include<math.h>#include<algorithm>using namespace std;int num[10];bool dfs(int step,int btop,int ctop){ if(step==9){ if(num[step]>btop||num[step]>ctop){ return true; } else return false; } bool b = false; bool c = false; if(num[step]>btop){b = dfs(step+1,num[step],ctop);} if(num[step]>ctop){c = dfs(step+1,btop,num[step]);} return (b||c);}int main(){ int t; cin>>t; while(t--){ memset(num,0,sizeof(num)); for(int i = 0;i<10;i++){ cin>>num[i]; } bool ans = dfs(0,0,0); if(ans){cout<<"YES"<<endl;continue;} else{cout<<"NO"<<endl;continue;} }}
0 0
- aoj 0033 ball DFS
- aoj 0033 Ball(dfs)
- [DFS] AOJ 0033 Ball
- AOJ 0033 DFS
- AOJ 0033 Ball (dfs)
- Aoj 0033 Ball【dfs枚举】
- AOJ 0033: Ball(dfs )
- AOJ 0033 ball+AOH 0118Property Distribution (DFS)
- AOJ 0118 Property Distribution (DFS)
- AOJ 0525 Osenbei (dfs)
- [DFS] AOJ 0118 Property Distribution
- Aoj 0118 Property Distribution【dfs】
- AOJ 0118 Property Distribution 【DFS】
- 【AOJ 869】迷宫(DFS)
- AOJ 0033
- AOJ 0033
- AOJ 455 DFS+记忆化搜索
- AOJ 0118 Property Distribution (dfs)
- Codeforces Round #364 (Div. 2), problem: (B) Cells Not Under Attack
- java 转义字符
- Codeforces Round #364 (Div. 2), problem: (D) As Fast As Possible
- mac Access denied for user 'root'@'localhost' (using password: YES)
- toggle 切换
- AOJ 0033 DFS
- Java中访问权限控制
- 内存映射原理
- Session入Redis
- AOJ 0558 BFS
- Codevs 4600 [NOI2015]程序自动分析
- Hygieia 部署指南(1)介绍篇
- 除法
- javascript中eval解析JSON字符串