码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 1185G1 状压dp

时间:2019-07-10 15:18:46      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:its   i++   fine   type   cti   bitset   状压   tor   ace   

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

标签:its   i++   fine   type   cti   bitset   状压   tor   ace   

原文地址:https://www.cnblogs.com/buerdepepeqi/p/11163681.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!