Solved Pro.ID Title Ratio(Accepted / Submitted)
  1001 Acesrc and Cube Hypernet 7.32%(3/41)
  1002 Acesrc and Girlfriend 4.35%(2/46)
  1003 Acesrc and Good Numbers            暴力打表 24.80%(213/859)
  1004 Acesrc and Hunting 21.74%(90/414)
  1005 Acesrc and String Theory 23.46%(38/162)
  1006 Acesrc and Travel                换根树形DP 12.01%(123/1024)
  1007 Andy and Data Structure 0.85%(1/117)
  1008 Andy and Maze                  随机染色+状压DP 15.71%(33/210)
  1009 Calabash and Landlord 18.99%(613/3228)
  1010 Quailty and CCPC 33.48%(1060/3166)
  1011 Roundgod and Milk Tea 17.70%(776/4384)

1006 Acesrc and Travel

换根树形DP

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/
const int maxn = 1e5+;
int a[maxn],b[maxn];
vector<int>mp[maxn];
int n;
ll dpa[maxn][], dpb[maxn][];
///dpa[u][0]表示a从u开始选最大所能得,需要从dpb最小的转移过来,实际是个最小值
///dpa[u][1] 表示次小值。
///dpb[u][0]表示b的,它只能从dpa最大的转移过来,实际上是个最大值。
///dpb[u][1]表示次大值 int sona[maxn], sonb[maxn];
void dfs1(int u, int fa) {
dpa[u][] = dpa[u][] = inff;
dpb[u][] = dpb[u][] = -inff;
sona[u] = sonb[u] = ;
for(int v : mp[u]) {
if(v == fa) continue;
dfs1(v, u);
if(dpb[v][] + a[u] - b[u] <= dpa[u][]) {
dpa[u][] = dpb[v][] + a[u] - b[u]; if(dpa[u][] < dpa[u][]) {
swap(dpa[u][] , dpa[u][]);
sona[u] = v;
}
}
if(dpa[v][] + a[u] - b[u] >= dpb[u][]) {
dpb[u][] = dpa[v][] + a[u] - b[u];
if(dpb[u][] > dpb[u][]) {
swap(dpb[u][], dpb[u][]);
sonb[u] = v;
}
}
}
///度数为1的节点需要特殊判断,还要区分根节点和叶子节点
if(mp[u].size() <= && fa != ) {
dpa[u][] = dpb[u][] = a[u] - b[u];
}
}
ll ans;
ll cupa[maxn], cupb[maxn];
void dfs2(int u, int fa) { ll tmp = min(dpa[u][], cupa[u]); if(mp[u].size() == && fa) tmp = cupa[u];
ans = max(ans, tmp);
for(int v : mp[u]) {
if(v == fa) continue;
cupa[v] = max(cupb[u], dpb[u][ sonb[u] == v ? : ]) + a[v] - b[v];
cupb[v] = min(cupa[u], dpa[u][ sona[u] == v ? : ]) + a[v] - b[v];
dfs2(v, u);
}
}
int main(){
int T; scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i=; i<=n; i++) scanf("%d", &a[i]);
for(int i=; i<=n; i++) scanf("%d", &b[i]);
for(int i=; i<n; i++) {
int u,v;
scanf("%d%d", &u, &v);
mp[u].pb(v);
mp[v].pb(u);
} dfs1(, );
ans = dpa[][];
if(mp[].size() == ) cupa[] = cupb[] = a[] - b[];
else cupa[] = inff, cupb[] = -inff; dfs2(, );
printf("%lld\n", ans);
for(int i=; i<=n; i++) mp[i].clear();
}
return ;
}

1008 Andy and Maze

用到了color coding技巧。

参考和学习

/*
* @Author: chenkexing
* @Date: 2019-08-16 22:30:07
* @Last Modified by: chenkexing
* @Last Modified time: 2019-08-16 23:30:32
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <ctime>
#include <random>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, ll> p3;
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
mt19937 rnd(time());
const int maxn = 1e4+;
struct E
{
int u,v,w;
}edge[maxn];
int col[maxn];
int n,m,k;
ll dp[maxn][];
ll randgao() {
for(int i=; i<=n; i++) col[i] = rnd() % k; for(int i=; i<=n; i++){
for(int j=; j<( << k) ; j++) {
dp[i][j] = -inff;
}
int j = ( << col[i]);
dp[i][j] = ;
}
for(int j = ; j < ( << k) ; j++ ) {
for(int i=; i<=m; i++) {
int u = edge[i].u, v = edge[i].v, w = edge[i].w;
if((j & ( << col[u])))
dp[u][j] = max(dp[u][j], dp[v][j ^ ( << col[u])] + w);
if((j & ( << col[v])))
dp[v][j] = max(dp[v][j], dp[u][j ^ ( << col[v])] + w); }
} int up = ( << k) - ; ll res = -inff; for(int i=; i<=n; i++) res = max(res, dp[i][up]); return res == -inff ? - : res;
}
int main(){
int T; scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &n, &m, &k);
for(int i=; i<=m; i++) {
scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
}
ll ans = -;
for(int rep = ; rep <= ; rep++){
ans = max(ans, randgao());
}
if(ans == -) puts("impossible");
else printf("%lld\n", ans);
} return ;
}

2019DX#8的更多相关文章

  1. 2019DX#10

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Minimum Spanning Trees 22.22%(2/9)   1002 Lin ...

  2. 2019dx#9

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Rikka with Quicksort 25.85%(38/147)   1002 Ri ...

  3. 2019dx#7

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 A + B = C 10.48%(301/2872)   1002 Bracket Seq ...

  4. 2019DX#6

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Salty Fish 16.28%(7/43)  OK 1002 Nonsense Tim ...

  5. 2019DX#5

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 fraction 辗转相除 4.17%(7/168) ok  1002 three arr ...

  6. 2019dx#4

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 AND Minimum Spanning Tree 31.75%(1018/3206)   ...

  7. 2019DX#3

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Azshara's deep sea 凸包 6.67%(6/90)  

  8. 2019DX#2

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Another Chess Problem 8.33%(1/12)   1002 Beau ...

  9. 2019DX#1

    1001 Blank 题意 有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个.问颜色个数的方案数. 思路 DP 四维的DP,利用滚动数组优化一维空 ...

随机推荐

  1. 「玩转Python」打造十万博文爬虫篇

    前言 这里以爬取博客园文章为例,仅供学习参考,某些AD满天飞的网站太浪费爬虫的感情了. 爬取 使用 BeautifulSoup 获取博文 通过 html2text 将 Html 转 Markdown ...

  2. ld: library not found for -

    这几天在做微信登录,总是遇到这个问题,详细如下: ld: library not found for -lWeChatSDK clang: error: linker command failed w ...

  3. 后台post注入爆密码

    后台登陆框post注入按照注入的方式属于post,和前台搜索型post注入.文本框注入类似,由于目前主流的注 入工具除了穿山甲等较新工具以外几乎都是get注入,尤其是对于这种后台账户型post注入式无 ...

  4. Docker系列开篇之Virtual Machine VS Container(一)

    前言 本节开始我们正式进入Docker系列,网上关于Docker相关文章如数家珍,写博客至今,我也一直在朝着如何写出通俗易懂且不枯燥的文章这个目标前进,喃喃自语的同时也希望看到文章的童鞋能明白我在讲什 ...

  5. mysql 查询结果显示行号

    mysql 查询时,不像oracle那样,可以直接用 rownum 显示结果行号. 可以用定义用户变量来实现 set @myrnum = 0; select (@myrnum := @myrnum + ...

  6. HTML/CSS:图片居中(水平居中和垂直居中)

    css图片居中(水平居中和垂直居中) css图片居中分css图片水平居中和垂直居中两种情况,有时候还需要图片同时水平垂直居中, 下面分几种居中情况分别介绍: css图片水平居中 1.利用margin: ...

  7. 洛谷 P1120 小木棍

    题意简述 给出n个数,求最小的l,使n个数可分成若干组,每组和都为l. 题解思路 暴力搜索+剪枝 代码 #include <cstdio> #include <cstdlib> ...

  8. 从SpringBoot构建十万博文聊聊高并发文章浏览量设计

    前言 在经历了,缓存.限流.布隆穿透等等一系列加强功能,十万博客基本算是成型,网站上线以后也加入了百度统计来见证十万+ 的整个过程. 但是百度统计并不能对每篇博文进行详细的浏览量统计,如果做一些热点博 ...

  9. 实现API管理系统的几个重要关键词

    管理API的需求源自于Web API开展业务.从2006年开始,然后逐渐成熟,并在2016年之前进入市场.无论是通过代理现有API的管理网关.本身作为用于部署API本身的网关的一部分,还是作为连接层在 ...

  10. 右键新建 .md

    右键新建 .md 文件 声明:虽然我成功了,并且右键出来了两个,但是在添加 .html 的过程中又失败了,找不到解决办法. win + r --> regedit --> enter 点击 ...