NYOJ 491 dfs() (水)
来源:互联网 发布:java的游戏引擎 编辑:程序博客网 时间:2024/05/12 18:30
额,,纪念一下,,这是这段时间做搜索题做得最快的一次,也是做的最清楚了
题意:
不说了,很清楚,
思路:
深搜
枚举第一行,然后生成下一行,会超时,打个表
代码:(打表)
#include <stdio.h>#include<string.h>#include <iostream>#include <algorithm>using namespace std;int n,m,cn;int vis[29];char str[40],s[40];void chuly(int t) // 计算数量{ strcpy(s+1,str+1); int suma,sumb = suma = 0; while(t) { for(int i=1;i<=t;i++) { if(s[i]=='+') suma++; if(s[i]=='-') sumb++; } for(int i=1;i<t;i++) if(s[i]==s[i+1]) s[i]='+'; else s[i]='-'; t--; } if(suma==sumb)cn++;}void dfs(int count) // 深搜枚举{ if(count==n+1) { chuly(n); return; }; if(!vis[count]) { vis[count] = 1; str[count] = '+'; dfs(count+1); str[count] = '-'; dfs(count+1); vis[count] = 0; }}int main(){ //freopen("Output.txt","w",stdout); for(int i=1;i<=19;i++) { n = i; memset(vis,0,sizeof(vis)); cn = 0; dfs(1); printf("%d,",cn); }}
代码:(表)
#include<stdio.h>int main(){ int ds[20]={0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757}; int n; while(~scanf("%d",&n)) { printf("%d\n",ds[n]); }}
- NYOJ 491 dfs() (水)
- nyoj--491--幸运三角形(dfs)
- nyoj Thepartialsumproblem(DFS)
- nyoj 素数环(dfs)
- nyoj素数环(dfs)
- nyoj 587 blockhouses(DFS)
- 素数环 nyoj (dfs)
- NYOJ 587 blockhouses (DFS)
- NYOJ 1129 Salvation (DFS)
- NYOJ 499迷宫(DFS)
- nyoj 水池数目(DFS)
- NYOJ 499 迷宫(DFS)
- nyoj 677 碟战 (dfs)
- nyoj 1276 机器设备(DFS)
- NYOJ 491 幸运三角(dfs+打表)
- NYOJ--491--dfs(打表水过)--幸运三角形
- [DFS] NYOJ
- nyoj 491 幸运三角形 【DFS】+【打表】
- linux中读取目录的内容
- android 开源项目记录
- Android Fragment完全解析,关于碎片你所需知道的一切
- C++构造函数虚拟化
- 宏中"#"和"##"的用法
- NYOJ 491 dfs() (水)
- asp带刷新的验证码代码
- QT界面美化
- &和&&的区别
- USB otg 学习笔记
- php你的验证码安全么?
- String.getBytes()时发生了什么
- eclipse常见问题
- HDU1565 方格取数(1)网络流