题目: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. shell脚本学习(1)入门

    1脚本语言和编译型语言的区别:编译型的要从源码转换成目标代码,多运行于底层.脚本语言有解释器读入程序代码, 转成内部形式再执行. 2脚本语言,写的时间快,一般有awk,pwel, python Rub ...

  2. qt学习(二):启动画面

    打开一个软件,都会有启动画面. 现在去体验如何实现启动画面:输入图,装载,延时,下一张主部件图 在main.Cpp中实现启动时桌面图片. #include <QtGui/QApplication ...

  3. MDK(keil)4.7中文注释乱码解决

    由于编码使用不统一导致别的开发环境下的文件在MDK(keil)下打开中文显示乱码,解决这一问题需要进行码制转换, 可以先将欲打开的文件转换成UTF-8格式(如在notepad中进行转换),也可以在打开 ...

  4. Delphi RegisterHotKey 设置系统热键

    Symbolic constant name Value (hexadecimal) Keyboard (or mouse) equivalent VK_LBUTTON 01 Left mouse b ...

  5. (转)Maven创建webapp项目无法修改web版本的问题

    maven创建的web app,默认使用的servlet版本是2.3,默认不支持JSTL,为了默认支持JSTL表达式,需要升级servlet到3.0 转:http://blog.sina.com.cn ...

  6. 兼容iphone x刘海的正确姿势

    在 ios 11 中我们可以使用 viewport-fit=cover + safe-area-inset-*. 那么是不是 ios11 以下就用不了这些了呢?是的,但你见过 iphone x+ 有 ...

  7. 83、Tensorflow中的变量管理

    ''' Created on Apr 21, 2017 @author: P0079482 ''' #如何通过tf.variable_scope函数来控制tf.ger_variable函数获取已经创建 ...

  8. 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)

    题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...

  9. PAT_A1097#Deduplication on a Linked List

    Source: PAT A1097 Deduplication on a Linked List (25 分) Description: Given a singly linked list L wi ...

  10. apiDoc部署搭建

    apiDoc介绍: 目前,越来越多的项目进行前后端分离,那么就有需要比较规范的来管理API文档.而apiDoc这个API文档管理器,可以根据你项目代码的注释来进行自动生成API文档.同时支持C#.Ja ...