codeforces 1185G1 状压dp
Posted buerdepepeqi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 1185G1 状压dp相关的知识,希望对你有一定的参考价值。
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
define ls rt<<1
define rs rt<<1|1
define lson l,mid,rt<<1
define rson mid+1,r,rt<<1|1
define bug printf("*********\n")
define FIN freopen("input.txt","r",stdin);
define FON freopen("output.txt","w+",stdout);
define IO ios::sync_with_stdio(false),cin.tie(0)
define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
define forn(i, n) for (int i = 0; i < int(n); i++)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
struct EDGE
int v, nxt;
edge[maxn << 1];
int head[maxn], tot;
void add_edge(int u, int v)
edge[tot].v = v, edge[tot].nxt = head[u], head[u] = tot++;
int dp[1 << 16][4];
int t[maxn], g[maxn];
int main()
ifndef ONLINE_JUDGE
FIN
endif
int n, T;
scanf("%d%d", &n, &T);
for(int i = 0; i < n; i++)
cin >> t[i] >> g[i];
g[i]--;
int result = 0;
dp[0][3] = 1;
for(int sta = 0; sta < 1 << n; sta++)
for(int i = 0; i < 4; i++)
for(int j = 0; j < n; j++)
if (g[j] != i && ((sta & (1 << j)) == 0))
dp[sta ^ (1 << j)][g[j]] = (dp[sta ^ (1 << j)][g[j]] + dp[sta][i]) % mod;
int sum = 0;
for(int j = 0; j < n; j++)
// debug1(sum);
if (sta & (1 << j))
sum += t[j];
if (sum == T)
result = (result + dp[sta][i]) % mod;
cout << result << endl;
return 0;
以上是关于codeforces 1185G1 状压dp的主要内容,如果未能解决你的问题,请参考以下文章