这题真的有2500分吗。。。 难以置信。。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, k, a[], b[], dp[ << ];
bool ban[ << ];
LL dis[ << ]; inline void add(int& a, int b) {
a += b; if(a >= mod) a -= mod;
} int main() {
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", &a[i]);
scanf("%d", &k);
for(int i = ; i < k; i++) scanf("%d", &b[i]);
for(int S = ; S < ( << n); S++) {
for(int i = ; i < S; i++) {
if(S >> i & ) {
dis[S] = dis[S ^ ( << i)] + a[i];
break;
}
}
for(int i = ; i < k; i++) {
if(dis[S] == b[i]) {
ban[S] = true;
break;
}
}
}
dp[] = ;
for(int S = ; S < ( << n); S++) {
if(ban[S]) continue;
for(int i = ; i < n; i++) {
if(S >> i & ) {
add(dp[S], dp[S ^ ( << i)]);
}
}
}
printf("%lld\n", dp[( << n) - ]);
return ;
} /*
*/

Codeforces 327E Axis Walking 状压dp的更多相关文章

  1. CodeForces 327E Axis Walking(状压DP+卡常技巧)

    Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...

  2. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  3. Codeforces 917C - Pollywog(状压 dp+矩阵优化)

    UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...

  4. Codeforces 79D - Password(状压 dp+差分转化)

    Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...

  5. Codeforces 544E Remembering Strings 状压dp

    题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...

  6. codeforces 21D. Traveling Graph 状压dp

    题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...

  7. Codeforces 895C - Square Subsets 状压DP

    题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...

  8. Codeforces ----- Kefa and Dishes [状压dp]

    题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...

  9. CodeForces 907E Party(bfs+状压DP)

    Arseny likes to organize parties and invite people to it. However, not only friends come to his part ...

随机推荐

  1. 表格重新加载 where 携带上次值问题

    表格重载两种方式: 方式一: tableIns.reload(options)   注意这种方式的重载是不会携带上次数据加载时的where值     //使用 第一次渲染返回的对象 var table ...

  2. Javaweb中提到的反射浅析(附源码)

    反射:一个jdk5.0的新特性,高级运用.在后期的框架中,这个是一大重点,现在估计我们都不会太多的接触他的.但是为了后面的铺垫,我想还是先了解一下: 先构造一个类,然后我们用反射来获取,调用里面的方法 ...

  3. requsets模块和beautifulsoup模块

    2.requests模块方法 requests是基于Python开发的HTTP库,使用Requests可以轻而易举的完成浏览器可有的任何操作. request.get() request.post() ...

  4. float导致出现大面积空白

    float导致出现大面积空白,解决方法: *{ padding: 0; margin: 0; overflow:hidden; }

  5. Wannafly挑战赛17D 01序列2

    传送门 先考虑二进制下为3倍数的数的共同特点自己手玩去,可以发现这些数奇数二进制位上的1个数(记为\(a\))和偶数二进制位上的1个数(记为\(b\))在模3意义下相等(\(a \equiv b (m ...

  6. ubuntu12.04+cuda6.0+caffe(新版)的安装

    参照两位的博客 http://caffe.berkeleyvision.org/    官网 http://blog.csdn.net/u013476464/article/details/38071 ...

  7. JavaScript练习 - 正反选练习

    正反选练习 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  8. Django学习手册 - cookie / session

    cookie """ cookie属性: obj.set_cookie(key,value,....) obj.set_signed_cookie(key,value,s ...

  9. 实例详析ImageView的adjustViewBonds和scaleType

    android:adjustViewBounds是否保持宽高比.需要与maxWidth.MaxHeight一起使用,否则单独使用没有效果. 设置View的最大高度,单独使用无效,需要与setAdjus ...

  10. Java 集合系列0、概述

    概述: Collection 框架中 从最上层的核心主干可以看到:Iterator.Collection.Map 三个接口(拓展思考1)1.Collection 接口:主要包括了集合中的一些常用操作, ...