28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include iostream usingnamespacestd; classbingchaji { public: bingchaji() { init(); } intfather[200]; voidinit() { for(inti=0;i200;i++) father[i]=i; } voidunit(intu,intv) { father[getfather(u)]=father[getfather(v)]; } intgetfather(intv) { if(father[v]==v) returnv; returnfather[v]=getfather(father[v]); } boolsame(intu,intv) { returngetfather(u)==getfather(v); } }color[200]; intmain() { intn,m; cinnm; for(inti=1;i=m;i++) { intu,v,c; cinuvc; color[c]unit(u,v); } intk; cink; for(inti=1;i=k;i++) { intu,v; intres=0; cinuv; for(intj=1;j=m;j++) { if(color[j]sa
《一闪一闪亮星星》破4项影史纪录 比亚迪史上最大收购案全部完成 乌方称俄军导弹袭击已致39死 路人吐槽跨年活动布置像灵堂 俄军为何突然对乌发
In the second sample, the optimal route is 0→8→15→21→28 (+1 gem)→36 (+1 gem)→45 (+1 gem)→55 (+1 gem)→66 (+1 gem)→78 (+1 gem)→ In the third sample, the optimal route is 0→7→13→18 (+1 gem)→24 (+2 gems)→30 (+1 gem)→ 状态转移方程dp[pos][len]=max(dp[pos+len-1][len-1],dp[pos+len][len],dp[pos+len+1][len+1])+a[pos] pos和len的范围都是1~故不可能开这么大的数组,故对于len2000,由于状态数比较少,直接dfs就可以了 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 4