题目: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. layui导出表格全部数据

    layui自带的导出表格,只能导出当前页面,如果当前页包含全部数据,那不就是导出全部数据了吗,所以我给导出事件单独定义了一个请求,当触发这个请求时,在后台查询数据时不要按接收的page 和 limit ...

  2. CEF的备忘笔记

    CEF: Chromium Embeded Framewrok;  (Chromium嵌入式框架)可以在PC(Linux,MacOS,Windows)上把Chromium的内核嵌入到应用程序的框架: ...

  3. JS基础入门篇(二十四)—DOM(下)

    1.offsetLeft/offsetTop offsetLeft/offsetTop : 到定位父级节点的距离. <!DOCTYPE html> <html lang=" ...

  4. Google recaptcha在webform中的使用

    开源项目 https://github.com/tanveery/recaptcha-net   这个的NuGet下载量最高 https://github.com/PaulMiami/reCAPTCH ...

  5. JS-动态加载

    var s = document.createElement('script'); s.setAttribute('src', ''); s.setAttribute('type', 'text/ja ...

  6. 88、使用tensorboard进行可视化学习,查看具体使用时间,训练轮数,使用内存大小

    ''' Created on 2017年5月23日 @author: weizhen ''' import os import tensorflow as tf from tensorflow.exa ...

  7. upc组队赛4 Go Latin

    Go Latin 题目描述 There are English words that you want to translate them into pseudo-Latin. To change a ...

  8. ssh远程连接控制 linux 口令、密钥连接

    sshd服务提供两种安全验证的方法: 基于口令的安全验证:经过验证帐号与密码即可登陆到远程主机. 基于密钥的安全验证:需要在本地生成“密钥对”后将公钥传送至服务端,进行公共密钥的比较(相对安全). 首 ...

  9. js node.children与node.childNodes与node.firstChild,node,lastChild之间的关系

    博客搬迁,给你带来的不便,敬请谅解! http://www.suanliutudousi.com/2017/11/06/js-node-children%e4%b8%8enode-childnodes ...

  10. JPA接口整理归纳方法规则

    Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ...