题目: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. jq实现跟随鼠标点击移动的下划线效果

    效果如下: 1.html代码: <div class="center-left-tap"> <a href="javascript:void (0)&q ...

  2. redis配置文件详解-3

    redis3.0以上配置文件 #################################INCLUDES ################################### include ...

  3. PAT_A1093#Count PAT's

    Source: PAT A1093 Count PAT's (25 分) Description: The string APPAPT contains two PAT's as substrings ...

  4. elementui表格表头合并

    第一步:用多级表头,该删删 该减减 第二步:使用header-cell-style属性

  5. oracle查询不显示小数点前的0

    1.问题起源       oracle 数据库字段值为小于1的小数时,使用char类型处理,会丢失小数点前面的0       例如0.35就变成了.35 2.解决办法:用to_char函数格式化数字显 ...

  6. sass揭秘之@mixin,%,@function scss基本使用及操作函数

    sass揭秘之@mixin,%,@function: 地址:https://www.w3cplus.com/preprocessor/sass-mixins-function-placeholder. ...

  7. 引用so动态链接库的方法

    from ctypes import cdll lib = cdll.LoadLibrary('/home/zhengli/test/test.so') lib.func() 总结: 1.引用ctyp ...

  8. 4154: [Ipsc2015]Generating Synergy

    Description 给定一棵以1为根的有根树,初始所有节点颜色为1,每次将距离节点a不超过l的a的子节点染成c,或询问点a的颜色 区间修改单点查询kdtree #include<iostre ...

  9. 多线程实现奇偶统计v2 - 信号量实现

    #include <stdio.h> #include <stdlib.h> #include <time.h> #include "pthread.h& ...

  10. cenos7 下数据库相关操作

    1.Linux Centos7下如何确认MySQL服务已经启动 https://www.cnblogs.com/qianzf/p/7082484.html 2.CentOS 7上安装MySQL并配置远 ...