题目:http://codeforces.com/contest/1185/problem/G1

题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类型,相同的物]品不一样的顺序代表不同,问有多少个序列

思路:首先范围是15个,这里我们可以用状压来代表选择哪些物品,然后这里是说不能有连续相同的类型,这里我们贪心考虑不全,最开始我考虑的是组合数的插空法,当时

发现有很多细节,写不了,这样的话我们就只能改成dp,

我们设置dp[i][j]   代表i状态以j结尾的序列有多少个,这里我们用的是dp中 的我为人人形式

#include<bits/stdc++.h>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll n,m;
ll sum[<<],dp[<<][];
ll a[],b[];
ll add(ll x,ll y){
return x+y>=mod?x+y-mod:x+y;
}
int main(){
cin>>n>>m;
for(int i=;i<n;i++){
cin>>a[i]>>b[i];
}
for(int i=;i<(<<n);i++){
for(int j=;j<n;j++){
if((i>>j)&) sum[i]+=a[j];
}
}
for(int i=;i<n;i++) dp[<<i][i]=;//最开始只有一件物品的时候都是序列数为1
ll ans=;
for(int i=;i<(<<n);i++){
if(sum[i]==m){
for(int j=;j<n;j++){
if((i>>j)&){
ans=add(ans,dp[i][j]);
}
}
}
for(int j=;j<n;j++){
if(!((i>>j)&)) continue;
for(int k=;k<n;k++){
if(j==k) continue;//这里用当前二进制位1结尾推出其他的二进制位
if(!((i>>k)&)&&b[j]!=b[k]) dp[i|(<<k)][k]=add(dp[i|(<<k)][k],dp[i][j]);
}
}
}
cout<<ans;
}

Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)的更多相关文章

  1. Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)

    因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...

  2. Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP

    D. Little Pony and Harmony Chest   Princess Twilight went to Celestia and Luna's old castle to resea ...

  3. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  4. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

  5. Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)

    链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...

  6. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  7. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  8. Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)

    D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...

  9. Codeforces Round #568 Div. 2

    没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...

随机推荐

  1. CF1061E Politics E. Politics 解题报告

    CF1061E Politics E. Politics 考虑利用树的性质,因为是子树问题,所以放到dfs序上. 只考虑一个树,问题是每个区间选恰好\(k\)个.因为区间其实是子树,所以区间要么包含, ...

  2. [NOIP模拟测试30]题解

    A.Return 出题人大概是怕自己的中文十级没人知道,所以写了这么一个***题面.可能又觉得这题太水怕全场A掉后自己面子过不去,于是又故意把输出格式说的含糊不清.(鬼知道"那么输出-1&q ...

  3. iOS 109个Demo范例

    https://github.com/subdigital/nsscreencast 版权声明:本文为博主原创文章,未经博主允许不得转载.

  4. 【Java架构:基础技术】一篇文章搞掂:Maven

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文基于<Maven 实战>一书进行总结和扩展,大家也可以自行研读此书. 一.Maven简介 1.1.什么是Maven ...

  5. VMware 克隆 CenterOS 虚拟机

    前面介绍了VMware 安装CenterOS 6.9,现在再介绍下 VMware 克隆虚拟机,克隆虚拟机可以快速的创建虚拟机,免去重复安装的烦恼. 一.VMware 克隆 CenterOS 虚拟机 选 ...

  6. HTML-参考手册: HTML ISO-8859-1

    ylbtech-HTML-参考手册: HTML ISO-8859-1 1.返回顶部 1. HTML ISO-8859-1 参考手册 现代的浏览器支持的字符集: ASCII 字符集 标准 ISO 字符集 ...

  7. Linux NIO 系列(04-2) poll

    目录 一.select 和 poll 比较 二.poll API 附1:linux 每个进程IO限制 附2:poll 网络编程 Linux NIO 系列(04-2) poll Netty 系列目录(h ...

  8. git清理工作区

    git clean -f 这将删除所有未被追踪的文件 git rev-list

  9. SpringMVC入门及拦截器

    SSM最后一个框架springmvc,其实上手特别简单.但是我昨天看一个深入源码的视频,差点GG.其实以前学过很多东西,都忘了,不敢说学会,现在有了本书,看过一遍之后.多多少少记住一些,权当我会用了, ...

  10. 36-python基础-python3-字典与列表的区别

    (1)不像列表,字典中的表项是不排序的.名为 spam 的列表中,第一个表项是 spam[0].但字典中没有“第一个”表项. (2)确定两个列表是否相同时,表项的顺序必须相同,但在字典确定两个字典是否 ...