uva 11127(暴力)
题意:给出一个字符串,包含0、1、*,当中×是能够替换成0或者1的,假设字符串的某个子串S有SSS这种连续反复3次出现,不是Triple-free串,问给出的字符串能够形成多少个非Triple-free串。
题解:由于串长度最多31,所以能够暴力枚举每一位,边枚举边推断。
#include <stdio.h>
#include <string.h>
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;
}
uva 11127(暴力)的更多相关文章
- UVA 11754 (暴力+中国剩余定理)
题目链接: http://www.bnuoj.com/v3/problem_show.php?pid=20172 题目大意:有C个模方程,每个方程可能有k余数,求最小的S个解. 解题思路: 看见模方程 ...
- UVA 185(暴力DFS)
Roman Numerals The original system of writing numbers used by the early Romans was simple but cum ...
- 【每日一题】Squares UVA - 201 暴力+输出坑 + 读文件模板
题意 给你n*n的图,让你数正方形 题解:暴力for每个点,对于每个点从它出发顺时针走一个正方形.走完就ans[i]++; 坑:多输了一行******,然后在那里手摸样例,无限debug orz #d ...
- uva 11088 暴力枚举子集/状压dp
https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...
- UVA 11464 暴力+位运算 ***
题意:给你一个 n * n 的 01 矩阵,现在你的任务是将这个矩阵中尽量少的 0 转化为 1 ,使得每个数的上下左右四个相邻的数加起来是偶数.求最少的转化个数. 新风格代码 lrj书上说的很清楚了, ...
- UVa 725暴力求解
A - Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su Description Writ ...
- Uva 11491 暴力贪心
题意:给一个n长度的整数,删掉 k 个数字,使得剩下的数字最大. 分析:还剩 n-k 个数字,就是在原序列里面,相对顺序不变的情况下,这个n-k个数字组成的数最大. 感觉没有什么特别好的方法策略,看了 ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
随机推荐
- Pycharm 简单设置
- day03_11 if语句实现猜年龄01
老男孩猜年龄游戏 age_of_princal = 56 guess_age = int( input(">>:") ) #以下为伪代码 ''' if guess_ag ...
- match_parent, wrap_content, 和 fill_parent 区别联系
fill_parent -1 The view should be as big as its parent (minus padding). This constant is deprecat ...
- django html render_to_response
#coding=utf-8 from django.shortcuts import render from blog.models import BlogPost from django.short ...
- failed to allocate for range 0: no IP addresses available in range set: 172.20.xx.1-172.20.xx.254
今天遇到一个机器上的Pod 在创建以后一直处于Init 0/1的状态,进到这个节点查看其kubelet的状态,发现果然有问题 systemctl status kubelet .go:] Contai ...
- phpstorm 快速插入常用代码片段
- 【Luogu】P2219修筑绿化带(单调队列)
题目链接 这题各种边界判断恶心死人 就是单调队列在每行求出最小的.能装进A*B方块里的花坛 然后再在刚刚求出的那个东西里面跑一遍竖着的单调队列 然后……边界调了一小时 做完这题我深刻地感觉到我又强了 ...
- POJ 3037 Skiing
Skiing Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4810 Accepted: 1287 Special ...
- vue slot 插槽备忘
老是记不住插槽咋回事 记录下来备忘 父组件 <tab><template slot="boy" slot-scope="test">{{ ...
- Django ConnectionAbortedError WinError 10053 错误
因为ajax默认是异步提交,可是有时候我们会发现,本来要求请求马上出现,可是异步会导致后面突然再执行,这样就出问题了. (1)添加这样一段代码 $.ajaxSetup({ async : false ...