Codeforces 757D - Felicity's Big Secret Revealed
757D - Felicity's Big Secret Revealed
题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后面
不算一段。设剩下的段里面的最大值为max,若1-max都在这些段里面出现过则算一个有效划分,问你总共有多少有效划分,
答案对1e9+7取模。
写的时候感觉是个dp,单就是想不出来,看了题解说是状态压缩dp,把出现过哪些数字当做状态,这样才写出来的QAQ。
思路:因为n<=75,我们列一下,最大值肯定不会超过20,这样我们就能状态压缩了。
dp[ i ][ j ]表示,最后一条划分线在第 i 个数后面,状态为 j 的划分数。这样我们就可以枚举划分的第一个数,
再枚举这个段的长度k,如果这个段对应的十进制的值为w,那么状态转移方程为 dp[ i + k -1 ] [ j | ( 1 << ( w - 1 ) ) ]+=dp[ i - 1 ][ j ];
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=;
const int M=;
const ll mod=1e9+;
int dp[N][(<<M)+];//dp[i][j] 表示最后一个划分线在i后面状态为j的划分数。
int a[N],n,pow2[];
int work(int l,int r,int len)
{
int c=len-,ans=;
for(int i=l;i<=r;i++)
{
ans+=a[i]*pow2[c];
c--;
}
return ans;
}
int main()
{
int up=<<M;
pow2[]=;
for(int i=;i<=;i++) pow2[i]=pow2[i-]*;
cin>>n;
for(int i=;i<=n;i++) scanf("%1d",&a[i]);
for(int i=;i<=n;i++) dp[i][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<up;j++)
{
if(!dp[i-][j]) continue;
for(int k=;k<=n-;k++)//枚举长度最大不是5位 如00000001,这个wa了几次
{
if(i+k>n) break;
int w=work(i,i+k,k+);
if(w>) break;//这里不判断会RE
if(w>=) dp[i+k][j|(<<(w-))]=(dp[i+k][j|(<<(w-))]+dp[i-][j])%mod;
}
}
}
int ans=;
for(int i=;i<=n;i++)
{
int now=;
int p=;
for(int j=;j<=;j++)
{
p+=now;
ans=(ans+dp[i][p])%mod;
now*=;
}
}
cout<<ans<<endl;
return ;
}
Codeforces 757D - Felicity's Big Secret Revealed的更多相关文章
- CodeForces 757D Felicity's Big Secret Revealed(状压DP)
题意:给定一个01串,一个有效的n切割定义如下:一个横杠代表一次切割,第一条横杠前面的01串不算,最后一条横杠后面的01串不算,将两个横杠中的01串转化成十进制数字,假设这些数字的最大值是MAX且这些 ...
- 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 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 757D】Felicity's Big Secret Revealed
[题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...
- Codeforces 757C. Felicity is Coming!
C. Felicity is Coming! time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)
题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...
- Codeforces Round #391 A B C D E
A. Gotta Catch Em' All! 题意 从给定的字符串中选取字符,问可构成多少个\(Bulbasaur\) // 想到柯南里一些从报纸上剪汉字拼成的恐吓信_(:з」∠)_ Code #i ...
- ethereum/EIPs-1077 Executable Signed Messages
https://github.com/alexvandesande/EIPs/blob/ee2347027e94b93708939f2e448447d030ca2d76/EIPS/eip-1077.m ...
随机推荐
- Windows 与 Linux下关于端口不能访问的问题
自己写的一个HTTP文件服务器,在端口 50000上监听HTTP连接请求,在Eclipse里面将程序正常地启动之后,能够在自己的机器上(Eclipse启动该程序的机器上)访问 50000端口,即Fil ...
- Ubuntu18.04下vim的tab缩进设置为4个空格
在/etc/vim/vimrc最后添加如下内容 set ts = 4 set exbandtab set autoindent
- 使用ResourceBundle读取配置文件
在Java语言中,使用一种以.properties为扩展名的文本文件作为资源文件,该类型的文件的内容格式为类似: 12 #注释语句 some_key=some_value 形式.以#开头的行作为注释行 ...
- golang error信息转字符串 x := fmt.Sprintf("%s", err)
_, _, ch, err := m.ZkConn.ChildrenW(node) if err != nil { x := fmt.Sprintf("%s", err) if s ...
- json 不能 dumps Decimal 解决办法
class DecimalEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): ret ...
- JavaSE之Math类
下列哪个选项是正确计算42度(角度)的余弦值? double d=Math.cos(42) double d=Math.cosine(42) double d=Math.cos(Math.toRadi ...
- luogu P2331 [SCOI2005]最大子矩阵
传送门 \[\huge\mathit{warning}\] \[\small\text{以下说明文字高能,请心脏病,,,,,,人士谨慎观看,请未成年人在家长陪同下观看}\] 皮这一下很开心 其实是代码 ...
- 第16月第5天 performSelector afterDelay cancel dispatch_semaphore_wait
1. //不延时,可能会导致界面黑屏并卡住一会 [self performSelector:@selector(startScan) withObject:nil afterDelay:0.3]; - ...
- 7、完整版的strcpy函数
char * strcpy( char *strDest, const char *strSrc ) { assert( (strDest != NULL) && (strSrc != ...
- Project Euler Problem6
Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 ...