博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 11127(暴力)
阅读量:6883 次
发布时间:2019-06-27

本文共 1528 字,大约阅读时间需要 5 分钟。

题意:给出一个字符串,包含0、1、*,当中×是能够替换成0或者1的,假设字符串的某个子串S有SSS这种连续反复3次出现,不是Triple-free串,问给出的字符串能够形成多少个非Triple-free串。

题解:由于串长度最多31,所以能够暴力枚举每一位,边枚举边推断。

#include 
#include
const int N = 35;char str[N], str2[N];int n;long long res;bool judge(int cur) { for (int i = 1; i * 3 <= (cur + 1); i++) { int e = cur - i * 3, cnt2 = 0; for (int j = cur; j > cur - i; j--) { int cnt = 0; for (int k = j; k > e; k -= i) if (str2[j] != str2[k]) break; else cnt++; if (cnt == 3) cnt2++; else break; } if (cnt2 == i) return false; } return true;}void dfs(int cur) { if (cur == n) { res++; return; } if (cur == 0 || cur == 1) { if (str[cur] == '0' || str[cur] == '1') { str2[cur] = str[cur]; dfs(cur + 1); } else { str2[cur] = '0'; dfs(cur + 1); str2[cur] = '1'; dfs(cur + 1); } return; } str2[cur] = '0'; if (judge(cur)) { if (str[cur] == '0' || str[cur] == '*') dfs(cur + 1); } str2[cur] = '1'; if (judge(cur)) { if (str[cur] == '1' || str[cur] == '*') dfs(cur + 1); }}int main() { int cas = 1; while (scanf("%d", &n) == 1 && n) { scanf("%s", str); res = 0; dfs(0); printf("Case %d: %lld\n", cas++, res); } return 0;}

转载地址:http://tbnbl.baihongyu.com/

你可能感兴趣的文章
php中转义html标签
查看>>
jQuery.extend 函数详解
查看>>
The Nature of Lisp
查看>>
chineking / WeiboCrawler / wiki / Home — Bitbucket
查看>>
Java用native2ascii命令做unicode编码转换
查看>>
POST jpeg upload with AFNetworking
查看>>
wow 我的书单
查看>>
文件上传+截图+预览升级版-我们到底能走多远系列(23)
查看>>
C++ ORM - fg100emil的专栏 - 博客频道 - CSDN.NET
查看>>
html5之Canvas绘图工具基础介绍
查看>>
CSS:当鼠标移动到表格的某一行时改变其背景颜色
查看>>
在OEL5上安装配置Oracle Gird Control 10.2.0.5
查看>>
EXIT_SUCCESS_百度百科
查看>>
[转]C# 4.0 新特性
查看>>
HDU-4536 XCOM Enemy Unknown 枚举
查看>>
HDU 湫秋系列故事——安排座位 组和DP
查看>>
该不该让Google收录WordPress的目录页和标签页?
查看>>
Hypertable 0.9.7.3 发布,分布式数据库
查看>>
【leetcode】Best Time to Buy and Sell Stock
查看>>
JS判断浏览器类型
查看>>