51nod 1400 序列分解
来源:互联网 发布:网盘搜索软件 编辑:程序博客网 时间:2024/05/06 20:02
只有40长度,dfs一下就好。
由于剪枝,时间复杂度O(2^20)。
#include<bits/stdc++.h>int a[44],b[44],arr[44],n,flag;void dfs(int deep,int alen,int blen){if(deep==n||flag){flag=1;return;}if(alen==blen){a[alen+1]=arr[deep];dfs(deep+1,alen+1,blen);}else if(alen>blen){if(a[blen+1]==arr[deep]){b[blen+1]=arr[deep];dfs(deep+1,alen,blen+1);}if(alen<n/2){a[alen+1]=arr[deep];dfs(deep+1,alen+1,blen);}}else{if(b[alen+1]==arr[deep]){a[alen+1]=arr[deep];dfs(deep+1,alen+1,blen);}if(blen<n/2){b[blen+1]=arr[deep];dfs(deep+1,alen,blen+1);}}}int main(){int i,T;scanf("%d",&T);while(T--){scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&arr[i]);}flag=0;dfs(0,0,0);if(flag)printf("Good job!!\n");elseprintf("What a pity!\n");}}
0 0
- 51nod 1400 序列分解
- 51nod 1400 序列分解(DFS + 剪枝)
- 51nod 1400 序列分解(深搜)
- 51Nod-1400-序列分解
- 51 nod 1400 序列分解(dfs+剪枝)@
- 51nod oj 1400 序列分解 【dfs暴力】
- 51nod 1400 序列分解【Dfs+剪枝】好题~
- 51nod-序列分解(dfs)
- 51nod 1400 序列分解 阻止我的只有读题能力了
- 51nod 算法马拉松3 A:序列分解
- 51nod round3# 序列分解(折半枚举+字典树)
- 51nod 分解
- 51nod-1537分解
- 51NOD 1537 分解
- [51nod 1537]分解
- 51nod 1537 分解
- 51nod 40 序列分解 暴力dfs or 折半+字典树
- 51nod - 1573 分解 - 矩阵快速幂
- LTE-TDD HARQ(4)-上下行HARQ的特点
- selvelt四大域
- JAVA基础知识点(十六)--集合和数组中的工具类
- (32)参数传递
- hdu1824Let's go home
- 51nod 1400 序列分解
- acronym
- 优化MySQL方法
- 【Android图像处理】从相册选择一张图片并分享
- C语言位操作符
- 简单bfs
- 深入理解OkHttp源码(二)——获取响应
- 2016年11月16日 课堂笔记
- python一些基础面试题