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. Prometheus 整合 AlertManager

    简介 Alertmanager 主要用于接收 Prometheus 发送的告警信息,它很容易做到告警信息的去重,降噪,分组,策略路由,是一款前卫的告警通知系统.它支持丰富的告警通知渠道,可以将告警信息 ...

  2. yum源使用报错

    CentOS系统yum源使用报错:Error: Cannot retrieve repository metadata (repomd.xml) for repository: rpmforge. 服 ...

  3. GGPLOT2-plotly |让你的火山图“活”过来

    火山图(Volcano Plot)常用于展示基因表达差异的分布,横坐标常为Fold change(倍数),越偏离中心差异倍数越大;纵坐标为P值(P值),值越大差异越显着.原因得名也许的英文因为查询查询 ...

  4. 【Android】Genymotion 模拟器 Unable to create virtual device

    安装 Genymotion 模拟器的时候报了这个错误,如下: 后来找到了解决方法,见下图: 在 Setting -> Network, 勾选 Use HTTP Proxy, HTTP Proxy ...

  5. How to check all timestamps of a file

    A friend of mine she asked me how to check all timestamps of a file on an NTFS volume. She did not h ...

  6. 技巧:结合Zabbix与SNMP监控嵌入式设备

    在如何利用Zabbix监控网络设备三篇文章的前两篇中,我们介绍了如何通过Zabbix代理监控网络设备.但有些设备无法安装Zabbix代理,需要采用其他方法监控.需要考虑无法安装软件的嵌入式设备或应用程 ...

  7. .net持续集成测试篇之Nunit that断言

    系列目录 that是Nunit的新语法,语义上不如简单断言,使用上也更加复杂,但是其功能更加强大. 其基本语法如下代码片段示: [Test] public void DemoTest() { bool ...

  8. 控制台出现_ob_:Obsever

    我遇到一个问题:我的代码想让他点击之后得到经纬度坐标数组,然后我就这样写了 然而控制台却读取出了

  9. Eclipse中代码自动添加注释及代码注释模板

    介绍 为了提高代码的可读性以及为了有些代码有洁癖的人的需求,我们要从学生到职业进行迈进的过程中,必须把以前的那种代码可读性不高的习惯改掉,因为我们必须要与企业接轨.. 好了,废话不多说,反正就是提升自 ...

  10. JAVA基础知识(五)数据类型转换

     当使用 +.-.*./.%.运算操作时,遵循如下规则: 1.只要两个操作数中有一个是double类型的,另一个将会被转换成double类型,并且结果也是double类型: 2.如果两个操作数中有一个 ...