EZOJ #226
分析

我们可以建一个k层图,把dp转移的三维对应到每个点上,每个第k层点连向0层点
我们让第0层点为实点其余为虚点,只要碰到虚点就dfs到他连得所有实点再将实点入队即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
priority_queue<pair<int,int> >q;
bool vis[][][];
int d[],v[],a[],b[],n,m,K,res;
inline void go(int x,int y,int z){
if(vis[x][y][z])return;
vis[x][y][z]=;
if(x==m){
if(y==K&&z<n&&res+b[z]<d[z]){
d[z]=res+b[z];
q.push(make_pair(-d[z],z));
}
}else {
go(x+,y,z);
if(y<K)go(x+,y+,z^(<<x));
}
}
int main(){
int i,j,k;
scanf("%d%d",&n,&K);
while((<<m)<n)m++;
memset(d,0x3,sizeof(d));
for(i=;i<n;i++){
scanf("%d",&v[i]);
if(v[i]>=)d[i]=v[i],q.push(make_pair(-d[i],i));
}
for(i=;i<n;i++)scanf("%d",&a[i]);
for(i=;i<n;i++)scanf("%d",&b[i]);
while(!q.empty()){
int x=q.top().second,y=-q.top().first;
cout<<y<<endl;
q.pop();
if(x<n){
if(y>d[x])continue;
q.push(make_pair(-y-a[x],x+n));
}else {
res=y;
go(,,x-n);
}
}
int Ans=;
for(i=;i<n;i++)Ans^=d[i];
cout<<Ans;
return ;
}
EZOJ #226的更多相关文章
- Android Weekly Notes Issue #226
Android Weekly Issue #226 October 9th, 2016 Android Weekly Issue #226 本期内容包括: 用Firebase做A/B Test; 用R ...
- 226. Invert Binary Tree(C++)
226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- C#版 - 226. Invert Binary Tree(剑指offer 面试题19) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - 2 ...
- centos 7 IP不能访问nginx Failed connect to 185.239.226.111:80; No route to host解决办法
服务器环境 centos 7.4 问题描述 1.可以ping通IP ,用IP访问nginx 不能访问,在服务器上curl localhost curl 185.239.226.111可以获得 [ro ...
- LeetCode:翻转二叉树【226】
LeetCode:翻转二叉树[226] 题目描述 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 题目 ...
- 市场上 MLCC 226 电容现象
市场上 MLCC 226 电容现象 三星 X7R 1206 没有 16V 也有人在卖. Y5V 当 X7R 卖. X5R 当 X7R 卖. 薄电容当厚的电容卖.
- <LeetCode OJ> 226. Invert Binary Tree
226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...
- x509: certificate is valid for 10.96.0.1, 172.18.255.243, not 120.79.23.226
服务器:阿里云服务器 master:120.79.23.226 node:39.108.131.246 系统:Centos 7.4 node节点加入集群中是报错: x509: certificate ...
随机推荐
- CentOS6.8编译安装LAMP
CentOS6.8编译安装Apache2.4.25.MySQL5.7.16.PHP5.6.29 初始化 #固定IP vi /etc/sysconfig/network-scripts/ifcfg-et ...
- Clustershell集群管理
在运维实战中,如果有若干台数据库服务器,想对这些服务器进行同等动作,比如查看它们当前的即时负载情况,查看它们的主机名,分发文件等等,这个时候该怎么办?一个个登陆服务器去操作,太傻帽了!写个shell去 ...
- [转]MySQL 经验集
-- my.ini -> 在 [mysqld] 节点下加入一行 skip-grant-tables 然后重启服务 -- 接下来无密码登录到 mysql 执行以下命令 use mysql show ...
- Servlet3.0的简单使用
Servlet3.0(WEB3.0)算是比较新的Servlet技术了,对应的JavaEE版本是6,虽然目前最新的版本是3.1,对应版本JavaEE7.我们目前使用的做多的还是Servlet2.5的东西 ...
- Change R source code
If you'd like to simply test out the effect of that change in an interactive R session, you can do s ...
- Ubuntu Server如何配置SFTP(建立用户监狱)
Ubuntu Server如何配置SFTP(建立用户监狱) SSH File Transfer Protocol是一个比普通FTP更为安全的文件传输协议.(参考资料:http://en.wikip ...
- Android屏幕适配方案——基于最小宽度(Smallest-width)限定符
转自:https://www.cnblogs.com/error404/p/3815739.html 一.关于布局适配建议 1.不要使用绝对布局 2.尽量使用match_parent 而不是fill_ ...
- mysql数据库忘记密码时如何登录
1.打开cmd命令提示符,进入上一步mysql.exe所在的文件夹即: 2.输入命令 mysqld --skip-grant-tables 回车,此时就跳过了mysql的用户验证 3.然后直接输入 ...
- 三、postman测试断言设置语法
postman的基本介绍跟基本的用法,在此就不做过多赘述,主要是受限于时间,网上有很多大神总结的已经算是很详尽了,给出链接并感谢大神的辛苦与奉献: postman基本用法:http://www.jia ...
- 装linux双系统
一般的电脑都是一个盘的,只要分个区给linux就行了,好装.大概可以看看这篇:http://jingyan.baidu.com/article/c275f6bacc3326e33c756743.htm ...