學大偉業 2017 國慶 Day1

2022-03-01 23:45:00 字數 2979 閱讀 7522

期望得分:100+100+20=220

實際得分:100+100+20=220

(好久沒有期望==實際了 ,~\(≧▽≦)/~)

對於 a。。。。。。。。a

如果 第1個a 後面出現的第1個b~z 是右端點,且在第2個a之前,那麼有貢獻

如果 第2個a 前面出現的第1個b~z 是左端點,且在第1個a之後,那麼有貢獻

最後的貢獻/2

dis[i][j] 表示 到第i個點,用了j次傳送的最快時間

堆優化的dijkstra

相當於把樹分成許多塊,每乙個塊的大小》=k,求分塊方案數

樹上揹包

dp[i][j] 以i為根子樹內,塊的大小為j的方案數

g[j] 當前大小為j的塊的方案數

cnt[i] 以i為根節點的塊,大小》=k的方案數

假設當前正在合併u的子節點 v

v所在塊 如果本身就》=k,那麼v可以不併入u,g[j]=cnt[v]*dp[u][j]

列舉已經與u合併的塊的大小j

列舉v所在塊的大小h

g[j+h]+=dp[x][j]*dp[v][h]

合併u和v,把g賦給dp

最後處理完u的時候更新cnt

注意師最後合併,這樣可以使時間複雜度降到 n^2

相當於每對點只在lca處有貢獻

#include#include

using

namespace

std;

#define n 5001

#define mod 786433

int front[n],to[n<<1],nxt[n<<1

],tot;

intsiz[n],dp[n][n],g[n],cnt[n];

intk;

void read(int &x)

}void add(int u,int

v)void

init()

}void dfs(int x,int

y)

for(int i=k;i<=siz[x];i++) cnt[x]+=dp[x][i],cnt[x]%=mod;

}int

main()

view code

2^n  20分暴力

#include#include

#include

using

namespace

std;

#define n 5001

intn,k;

int front[n],to[n<<1],nxt[n<<1],from[n<<1

],tot;

intans,cnt;

bool

use[n];

intsiz[n];

void read(int &x)

}void add(int u,int

v)void

init()

}void dfs2(int x,int

y)void

judge()

ans++;

}void dfs(int

x) dfs(x+2

); use[x]=use[x+1]=true; dfs(x+2); use[x]=use[x+1]=false;}

intmain()

view code

國慶DAY1訓練

j 模擬 題意 移動數字 記錄一下每個數字的位置 然後如果和0的距離為1 則交換 include using namespace std struct node p 1020000 pos intcal int x,int y int a 1020000 intmain while m for in...

國慶集訓Day1

題意 有 n 個數 a 1,a 2,a n 有m個數 b 1,b 2,b n 令 a a 1 times a 2 times times a n 令 b b 1 times b 2 times times b n 判斷 a 是否是 b 的倍數 輸入 n,m 輸出 yes no 做法 就是個一簡單的質...

學大偉業 Day 4 培訓總結

今天講的全是dp.不多廢話,先看一道經典的模板lis 最長不下降子串行 一.lis 給定乙個長度為n的數列,求最長上公升子串行 例 1 7 2 8 3 4 答案 1 2 3 4 1 include 突然想用萬能庫 23 using namespace std 45 const int maxn 10...