【codeforces 757D】Felicity's Big Secret Revealed
【题目链接】:http://codeforces.com/problemset/problem/757/D
【题意】
给你一个01串;
让你分割这个01串;
要求2切..n+1切;
对于每一种切法
所切成的各个部分的二进制,转成十进制之后;假设里面最大的数为m;
问1..m这些数字都出现的切法有多少种;
【题解】
可以算一下对于1个75位的数字来说;
最多只可能连续出现
从
1..20
你可以算一下1..20这20个数字的二进制形式恰好占74个;
不能再多一个数字了,因为21的二进制形式的长度肯定大于1啊;
所以写个状压DP;
f[i][j]
表示前i-1个位置是切的结果,第i个数字开始还没有被切,然后1..20这些数字数字被得到的状态为j的有多少种切法;
从i..n枚举切割点就好;
最后累加
f[i][2^j-1]
i∈[2..n+1],j∈[1..20]
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
const int M = (1<<20)+20;
const int MOD = 1e9+7;
int n,num[N][N],f[N][M],ans;
char s[N];
void add(int &a,int &b)
{
a = a+b;
if (a>=MOD) a-=MOD;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n);
rei((s+1));
rep1(i,1,n)
{
for (int j = i,k = 0;j <= n;j++)
if ((k=(k<<1)+s[j]-'0')>20)
break;
else
num[i][j] = k;
}
rep1(i,1,n)
{
f[i][0]++;
rep1(j,0,(1<<20)-1)
if (f[i][j])
rep1(k,i,n)
if (num[i][k])
add(f[k+1][j|1<<(num[i][k]-1)],f[i][j]);
}
rep1(i,2,n+1)
rep1(j,1,20)
add(ans,f[i][(1<<j)-1]);
pri(ans<<endl);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 757D】Felicity's Big Secret Revealed的更多相关文章
- Codeforces 757 D. Felicity's Big Secret Revealed 状压DP
D. Felicity's Big Secret Revealed The gym leaders were fascinated by the evolutions which took pla ...
- 【codeforces 757C】Felicity is Coming!
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 757D - Felicity's Big Secret Revealed
757D - Felicity's Big Secret Revealed 题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed
题目连接:http://codeforces.com/contest/757/problem/D D. Felicity's Big Secret Revealed time limit per te ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- JavaScript Patterns 2.1 Writing Maintainable Code
Revisiting the code after some time has passed requires: • Time to relearn and understand the proble ...
- 插入排序(1)——直接插入排序(insert sort)
假设有一组无序序列 R0, R1, ... , RN-1. (1) 我们先将这个序列中下标为 0 的元素视为元素个数为 1 的有序序列. (2) 然后,我们要依次把 R1, R2, ... , RN- ...
- Spark SQL中 RDD 转换到 DataFrame (方法二)
强调它与方法一的区别:当DataFrame的数据结构不能够被提前定义.例如:(1)记录结构已经被编码成字符串 (2) 结构在文本文件中,可能需要为不同场景分别设计属性等以上情况出现适用于以下方法.1. ...
- 【转】DOS与linux的断行字符
转自:http://www.2cto.com/os/201109/104833.html 今天配置linux的dns服务器,在配置的时候,在linux下修改配置文件感觉很麻烦,于是想到把配置文件拿到w ...
- Croppic插件使用介绍-asp.net
具体的参数使用和基本使用方式请看:http://www.uedsc.com/croppic-api.html 需要说明的几点: 1.支持两种上传方式: (1)先将原图上传至服务器,然后再次将切图信息传 ...
- 为什么现在改用int.TryParse了
以前一直用 int.Parse(x)或者 Convert.ToInt64(x),后来项目中发现如果x变量的值为null是,就报错了,哪怕我这样写 int.Parse(x=x??"0" ...
- TextOut与DrawText的区别
BOOL TextOut( HDC hdc, // 句柄 int nXStart, // 字符串的开始位置 x坐标 int nYStart, // 字符串的开始位置 y坐标 LPCTSTR lpStr ...
- UltraEdit(UE)window破解方法
安装UltraEdit(一路下一步,无难点)成功后,打开软件弹出如下使用模式提示信息. 关掉UltraEdit软件,同时 断本机网络.重新打开UltraEdit软件: 点击[输入许可证密 ...
- html5——css选择器
复习 div>p: 子代 div+p:div后面相邻的第一个p div~p: div后面所有的兄弟p 属性选择器 标志:[]:区别于id选择器:#,区别于类名选择器:. 特殊符号:^:开头 ...
- JS——offset
1.offsetWidth.offsetHeight返回盒子宽度和高度,包括padding与border,不包括margin 2.offsetLeft.offsetTop返回盒子距离定位盒子的x轴方向 ...