暴搜——51nod1400 序列分解
来源:互联网 发布:国安数据 编辑:程序博客网 时间:2024/05/17 14:17
题面:51nod1400
真的是大暴力
有人说直接暴搜加一个小剪枝就能过。。。
我的搜索策略有点奇怪
先讲一个错误的贪心:
我们开个数组q[i]记录一个子序列的状态
用一个指针p表示另一个子序列目前匹配到q[i]的第几位
然后匹配下一位的时候往后找到和这一位数值相同的最近位置
然后匹配上就好了,复杂度
但是这是错的,比如这组数据:
8
1 1 4 3 1 1 4 3
这就不行了
但是我们不要直接匹配上去,有两条路可以走,一是匹配,二是继续在前面一个串跟上去
这样就有两种策略了,搜索即可
时间复杂度
反正过了
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <iostream>#include <ctime>#include <map>#include <queue>#include <cstdlib>#include <string>#include <climits>#include <set>#include <vector>using namespace std;inline int read(){ int k=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();} return k*f;}int a[10001],q[10001],n;inline bool dfs(int l,int p,int r){ if(p==l)q[++l]=a[r++]; if(l>n/2)return 0; while(q[p+1]!=a[r]){ q[++l]=a[r];r++; if(r>n)return 0; } if(r==n&&p+1==l)return 1; if(dfs(l,p+1,r+1))return 1; else{ q[l+1]=a[r]; return dfs(l+1,p,r+1); }}int main(){ int T=read();while(T--){ n=read(); for(int i=1;i<=n;i++)a[i]=read(); q[1]=a[1]; puts(dfs(1,0,2)?"Good job!!":"What a pity!"); } return 0;}
阅读全文
1 0
- 暴搜——51nod1400 序列分解
- 51nod 1400 序列分解
- 算数基本定理——素因数分解序列生成
- EMD经验模态分解——分析时间序列
- 序列分解
- 51nod 1400 序列分解(DFS + 剪枝)
- Hash+折半枚举 51Nod1440 序列分解
- 51nod 1400 序列分解(深搜)
- 51Nod-1400-序列分解
- 51 nod 1400 序列分解(dfs+剪枝)@
- 51nod-序列分解(dfs)
- 矩阵分解——三角分解(Cholesky 分解)
- 时间序列分解入门
- 51nod 算法马拉松3 A:序列分解
- 51nod round3# 序列分解(折半枚举+字典树)
- 51nod oj 1400 序列分解 【dfs暴力】
- 51nod 1400 序列分解【Dfs+剪枝】好题~
- 时间序列分解算法:STL
- Java可变参数(转载)
- jzoj. 3889. 【NOIP2014模拟10.25B组】序列问题
- NIO非阻塞通信服务端部分代码
- hdu 2546 饭卡
- css样式
- 暴搜——51nod1400 序列分解
- java运算符之++、--
- 验证对象在创建时就会先调用(默认)构造方法
- 十分钟搞清字符集和字符编码
- STM32 心电滤波
- python 清新脏数据
- JZOJ 7.11 B组第一题 解题
- 利用Matlab开发基于XSENS Mtw传感器模块的行人室内实时定位系统的相关
- POJ 3173 Parkside's Triangle G++