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 ...
随机推荐
- 轻量级封装DbUtils&Mybatis之三MyBatis分页
MyBatis假分页 参考DefaultResultSetHandler的skipRows方法. 温馨提示:部分代码请参考轻量级封装DbUtils&Mybatis之一概要 解决方案 1)之前公 ...
- Erlang ets -- something about cache
都说用ets 写一个cache 太简单, 那就简单的搞一个吧, 具体代码就不贴了, 就说说简要的需求和怎么做(说设计有点虚的慌). 需求场景 >> 查询系统,对于主存储而言,一次写入多次查 ...
- struts全包导入问题
web.xml如下: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&q ...
- 20181122_C#中AOP_使用Unity实现AOP
一. 使用Unity的AOP实现 a) 整体项目截图: b) 添加Unity的Nuget包, 直接使用最新版就行, 需要添加两个 Unity 和 Unity.Interceptio ...
- Python Twisted系列教程19:改变之前的想法
作者:dave@http://krondo.com/i-thought-i-wanted-it-but-i-changed-my-mind/ 译者: Cheng Luo 你可以从”第一部分 Twis ...
- maven引入源码
选中要添加的源码的项目右键-->debug--->debugs-configurations-->source-->java project
- springboot-shiro chapter03 login
简介:这一节主要是集成shiro进行鉴权, 用户登录/退出 环境: IDEA15+JDK1.8+Maven3+ 代码: https://git.oschina.net/xinshu/springboo ...
- K2 Blackpearl中从数据库直接删除流程实例之K2Server表
转:http://www.cnblogs.com/dannyli/archive/2012/11/29/2794772.html /********************************** ...
- 利用CopyOnWriteArrayList解决并发修改异常问题
一.需求 多个线程再获取同一个集合里面的数据同时,修改集合中的数据. 二.有问题的写法 package com.duchong.juc; import java.util.ArrayList; imp ...
- ssm框架整合之Spring4+SpringMVC+Mybaties3之配置文件如何配置及内容解释--可直接拷贝使用--不定时更改之2017/4/29
经测试,需注意以下几点: 1,controller的自动扫描不能放在applicationContext.xml中,要放在spring-mvc.xml中.同样是<context:componen ...