这题真的有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. Syncfusion HTMLUI研究一

    HTMLUI可以加载HTML页面,并且相比WebKit等占用资源特别少 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona ...

  2. IDAPython学习(一)

    1.概述 IDAPython在IDA中集成了Python解释器,除了提供了Python功能外,使用这个插件还可以编写实现IDC脚本语言的所有Python脚本. IDAPython显著优势在于,它可以充 ...

  3. yolov3实践(二)

    这次给大家带来一个有趣的项目,项目主要是Python写的,基于Keras,backend是tf. 首先,当我们回顾视觉目标检测这个任务时,我们可能纠结于如何使这个项目变得更加work,我理解的更加wo ...

  4. mysql 案例 ~ 分析执行完的大事务

    一 简介:今天咱们来聊聊如何定位以及执行完的大事务 二 目的:通过分析binlog脚本来定位执行的大事务 三 分析脚本 mysqlbinlog --base64-output=decode-rows ...

  5. CSS font-family 各名称一览表

    参考链接:https://blog.csdn.net/cddcj/article/details/70739481

  6. dbms_metadata.get_ddl的用法(DDL)

    dbms_metadata包中的get_ddl函数 --GET_DDL: Return the metadata for a single object as DDL. -- This interfa ...

  7. 初识CPU卡、SAM卡/CPU卡简介、SAM卡简介 【转】

    初识CPU卡.SAM卡/CPU卡简介.SAM卡简介 IC卡按照接口方式可分为接触式卡.非接触式卡.复合卡:按器件技术可分为非加密存储卡.加密存储卡和CPU卡. 加密存储卡是对持卡人的认证,只有输入正确 ...

  8. Salt Document学习笔记2

    配置文件需修改的内容及注意点: Edit the master config file: 1. Uncomment and change the user: root value to your ow ...

  9. 查看tomcat运行状态

    实时查看tomcat并发连接数: netstat -na | grep ESTAB | grep 8080 | wc -l 实时查看apache并发连接数: netstat -na | grep ES ...

  10. 019_nginx upstream中keepalive参数

    一. TCP/IP State=>SYN_RECV,LISTEN,TIME_WAIT,ESTABLISHED,STREAM,CONNECTED,CLOSING (1)前端Nginx大量报no l ...