Codeforces 327E Axis Walking 状压dp
这题真的有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的更多相关文章
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- Codeforces 917C - Pollywog(状压 dp+矩阵优化)
UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...
- Codeforces 79D - Password(状压 dp+差分转化)
Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...
- Codeforces 544E Remembering Strings 状压dp
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...
- codeforces 21D. Traveling Graph 状压dp
题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...
- Codeforces 895C - Square Subsets 状压DP
题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...
- Codeforces ----- Kefa and Dishes [状压dp]
题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...
- CodeForces 907E Party(bfs+状压DP)
Arseny likes to organize parties and invite people to it. However, not only friends come to his part ...
随机推荐
- Linux 文件日志筛选操作
统计查看文件以及筛选日志 1.*.log 日志文件中 统计独立ip的个数: awk '{print $1}' test.log | sort | uniq | wc -l 2.#查询访问最多的前10个 ...
- Java SE 之 数据库操作工具类(DBUtil)设计
JDBC创建数据库基本连接 //1.加载驱动程序 Class.forName(driveName); //2.获得数据库连接 Connection connection = DriverManager ...
- WARN bzip2.Bzip2Factory: Failed to load/initialize native-bzip2 library system-native, will use pure-Java version
[root@hdp2 /root]#hadoop checknative -a 18/12/09 00:31:19 WARN bzip2.Bzip2Factory: Failed to load/in ...
- rem,em
任意浏览器的默认字体高都是16px.所有未经调整的浏览器都符合: 1em=16px.那么12px=0.75em,10px=0.625em.为了简化font-size的换算,需要在css中的body选择 ...
- Handler使用中可能引发的内存泄漏
https://my.oschina.net/rengwuxian/blog/181449 http://www.jianshu.com/p/cb9b4b71a820 http://blog.csdn ...
- java项目启动时执行指定方法
想到的就是监听步骤如下: 1.配置web.xml <listener> <listener-class>com.listener.InitListener</listen ...
- linux 网卡
查看网卡UUID:nmcli con show 或 nmcli con list 查看网卡mac地址:nmcli dev show 或 nmcli dev list 注:sho ...
- 007_linux显示一个文件的某几行(中间几行)
<1>从第3000行开始,显示1000行.即显示3000~3999行 cat -n filename | tail -n +3000 | head -n 1000 cat -n anaco ...
- mysql报错问题解决MySQL server PID file could not be found!
MySQL server PID file could not be found! 无法启动mysql服务 # service mysqld start MySQL server PID file c ...
- Ex 6_2 假设您准备一次长途旅行..._第五次作业
假设n个旅馆距离原点的距离存放在数组arr[0. . .n-1]中,punish[0. . .n-1]表示在某个旅馆停留时所受的的惩罚的最小值.当然在第一个旅馆停留时所受到的惩罚为0,即punish[ ...