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. Vue 报错 listen EADDRINUSE :::8080

    今天在重启vue项目的时候,发现报了错, listen EADDRINUSE :::8080错误提示 原因:因为另一个项目占用了8080端口,我直接在命令行npm run dev第二个项目,就给出了这 ...

  2. 遇见Python集合类型

    Python目前有两种内置集合类型,set和frozenset. Ⅰ.两者区别 set是可变的,没有哈希值,其内容可以使用add()和remove()这样的方法来改变,所以不能被用作字典的键或其他集合 ...

  3. C#async/await心得

    结论: 异步方法的方法签名要加 async,否则就算返回 Task 也是普通方法. 调用异步方法,可以加 await 或不加 await,两者方式都是马上返回,不加 await 得到的是 Task 对 ...

  4. Python基础总结之第十一天开始【再深入一下函数,重新认识一下】(新手可相互督促)

    感谢最近大家的关注,希望我的学习笔记对大家有帮助!也感谢各位的评论和推荐,请多多指教. 在重新认识函数之前,我们先看两个函数.一个是我们在前面笔记经常用到的print()  :另一个是input() ...

  5. Gridea+GitHub搭建个人博客

    某日闲余时间看到一篇介绍Gridea博客平台的文章,大概看了一下觉得此平台还不错,随即自己进入Gridea官网瞅了瞅.哇,这搭建过程也太简单了吧,比Hexo博客搭建要容易很多,而且还有后台管理客户端, ...

  6. String常量池和intern方法

    String s1 = "Hello"; String s2 = "Hello"; String s3 = "Hel" + "lo ...

  7. npm包开发与发布

    把通用的功能开发成npm包,便用使用和维护,更重要的是可以分享给广大的开发者,是不是很激动人心! 那么,步骤如下: 1.创建项目 创建项目目录,npm init ,根据需要输入配置信息(建完后也可以在 ...

  8. 有趣的RPC理解

    RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存在,如TCP或UDP,为通 ...

  9. Postman系列二:Postman中get接口实战讲解(接口测试介绍,接口测试流程,头域操作)

    一:接口测试介绍 接口测试:就是针对软件对外提供服务的接口输入输出进行测试,以及接口间相互逻辑的测试,验证接口功能和接口描述文档的一致性. 接口测试好处:接口测试通常能对系统测试的更为彻底,更高的保障 ...

  10. 史上最全面 Android逆向培训之__实战(hook微信)

    我的CSDN博客:https://blog.csdn.net/gfg156196   by--qihao 书接上文,上回说到了xposed,接下来就用一下,体验一下商业项目的赶脚…… 上一篇:史上最全 ...