锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
姣旇禌閭eぉ鎰熷啋錛岀涓棰樺氨寮勬檿浜嗭紝鐜板湪棰樿В鍑烘潵浜嗭紝琛ヤ笂鍚~
鏆傛椂鍙湁絎竴棰樼殑錛?/p>
Problem 6: Bobsledding [Brian Jacokes, 2009] Bessie has entered a bobsled competition because she hopes her hefty weight will give her an advantage over the L meter course (2 <= L <= 1,000,000,000). Bessie will push off the starting line at 1 meter per second, but her speed can change while she rides along the course. Near the middle of every meter Bessie travels, she can change her speed either by using gravity to accelerate by one meter per second or by braking to stay at the same speed or decrease her speed by one meter per second. Naturally, Bessie must negotiate N (1 <= N <= 100,000) turns on the way down the hill. Turn i is located T_i meters from the course start (1 <= T_i <= L-1), and she must be enter the corner meter at a speed of at most S_i meters per second (1 <= S_i <= 1,000,000,000). Bessie can cross the finish line at any speed she likes. Help Bessie learn the fastest speed she can attain without exceeding the speed limits on the turns. Consider this course with the meter markers as integers and the turn speed limits in brackets (e.g., '[3]'): | 1 2 3 4 5 6 7[3] |---+---+---+---+---+---+---+ | \ Start + 8 \ + 9 \ + 10 +++ 14 (finish) \ / 11[1] +---+---+ 12 13[8] Below is a chart of Bessie's speeds at the beginning of each meter length of the course: Max: 3 1 8 Mtrs: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Spd: 1 2 3 4 5 5 4 3 4 3 2 1 2 3 4 Her maximum speed was 5 near the beginning of meter 4. PROBLEM NAME: bobsled INPUT FORMAT: * Line 1: Two space-separated integers: L and N * Lines 2..N+1: Line i+1 describes turn i with two space-separated integers: T_i and S_i SAMPLE INPUT (file bobsled.in): 14 3 7 3 11 1 13 8 OUTPUT FORMAT: * Line 1: A single integer, representing the maximum speed which Bessie can attain between the start and the finish line, inclusive. SAMPLE OUTPUT (file bobsled.out): 5
棰樼洰鐪嬭搗鏉ユ尯澶嶆潅錛屽叾瀹炰富瑕佹槸姹傚嚭鍚勪釜turn澶勭殑鏈澶ч熷害錛屽垎鏋愬緱鍒版瘡涓猼urn鐨勬渶澶ч熷害闇瑕佹弧瓚充笁涓潯浠訛紝 M_i = min (S_i , t_i – t_{i-1} + M_{i-1} , S_k + t_k – t_i [for all k > i ] )
鍥犳澶勭悊姣忎竴涓猼urn閮借鏌ヨN涓猼urn N*N鐨勫鏉傚害鏄劇劧瀵逛簬澶ф暟鎹TLE鐨?/font>
閫嗗悜鎬濊冿紝濡傛灉鎴戜滑鍙嶈繃鏉ヨ冭檻錛屽浜庢瘡涓涓箣鍚庣殑turn鏉ヨ 濡傦細(xì)i 濡傛灉浠栨渶澶ч熷害涓?m_i
閭d箞 鍦╰urn i-1澶勶紝浠栦笉鑳借秴榪囩殑鏈澶ч熷害 m_{i-1} = min(S_i,m_i+t_i – t_{i-1});榪欐牱鎴愬姛鐨勬妸鍚庨潰涓や釜闄愬埗杞崲涓洪嗘帹鐨勭粨鏋滆屼笉鏄悜鍚庢煡璇?/font>
鍓╀笅鐨勯棶棰樹究鏄鏋滅煡閬撲袱涓猼urn涔嬮棿璺濈錛屼互鍙?qiáng)turn鐨勯熷害鏈澶у鹼紝濡備綍姹傚嚭涔嬮棿鐨勬渶澶у鹼紝鐢誨浘鏄劇劧鍙互寰楀埌涓縐嶇畻寮?maxspeed = min(s1,s2) + (dist2-dist1+abs(s1-s2))/2;
鎴栬?maxspeed = max(s1,s2) + (dist2 – dist1 – abs(s1-s2))/2;
娉ㄦ剰鍦ㄥ紑澶村拰緇撳熬鍔犲叆铏氭嫙鐨則urn灝卞彲浠ヤ簡
浠婂ぉ棰樿В鍑烘潵浜唦 鍏堢湅浜嗗ぇ姒傛濊礬 鐒跺悗鑷繁鍐欏嚭鏉ヤ簡~
棰樼洰錛?/font>
Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <= 100,000). The first player starts the game by taking the top one or two coins (C_1 and maybe C_2) from the stack. If the first player takes just the top coin, the second player may take the following one or two coins in the next turn. If the first player takes two coins then the second player may take the top one, two, three or four coins from the stack. In each turn, the current player must take at least one coin and at most two times the amount of coins last taken by the opposing player. The game is over when there are no more coins to take. Afterwards, they can use the value of the coins they have taken from the stack to buy treats from FJ, so naturally, their purpose in the game is to maximize the total value of the coins they take. Assuming the second player plays optimally to maximize his own winnings, what is the highest total value that the first player can have when the game is over? MEMORY LIMIT: 20 MB PROBLEM NAME: xoinc INPUT FORMAT: * Line 1: A single integer: N * Lines 2..N+1: Line i+1 contains a single integer: C_i SAMPLE INPUT (file xoinc.in): 5 1 3 1 7 2綆鍗曟潵璇村氨鏄袱涓漢杞祦鍙朿oins錛屾瘡涓漢姣忔鍙栧緱涓暟涓?- 2*n;n涓轟笂涓杞鏂瑰彇寰楁暟鐩紝姹備袱涓漢閮芥槸鐢ㄦ渶浣崇瓥鐣ワ紝鍏堝彇寰楅偅涓浼欐渶澶氳兘鎷垮埌澶氬皯紜竵銆傝矊浼煎彲浠ョ畻鏄畝鍗曞崥寮堣鐨勬濇兂鎬濊礬錛?/font>coins[1···N] 浠庝笅鍒頒笂 sum[1···N] 鍓╀笅 i涓殑鍜?/font>鎵懼埌鏃犲悗鏁堟х殑瀛愰棶棰樸傝冭檻鍦ㄨ繕鍓╀笅p涓挶甯佹椂鍊欑殑鎯呭喌錛屾鏃跺彲浠ユ嬁k涓挶鐢變簬鏉′歡錛宬鐨勫ぇ灝忓彈涓婁竴杞嬁鐨勪釜鏁癷鐨勯檺鍒?錛屾墍浠ユ垜浠鍔犱笂涓涓彉閲廼銆傚緱鍒?/font>dp[p][i]榪欎釜瀛愰棶棰樸傞偅涔堝鏄撳緱鍒?/font>dp[p][i]=max(1=<k<=i*2){SuM(p to p-k+1)+SuM(p-k to 1)-dp[p-k][k]}=max(1=<k<=i*2){sum[p]-dp[p-k][k]}鎸夌収榪欎釜鍙互寰楀埌涓涓狾錛圢^3錛夌殑綆楁硶oidsolve(){
for(inti=1;i<=N;i++)//鍓╀笅i涓?br> for(intj=1;j<=N;j++)//涓婁竴浜烘嬁浜唈 涓?br> for(intk=1;k<=j*2&&i-k>=0;k++){
dp[i][j]=max(dp[i][j],sum[1]-sum[i+1]-dp[i-k][k]);
}
ret=dp[N][1];
}涓夐噸閫掑綊 錛屾渶澶氬彲浠ヨ繃500鐨勬暟鎹噺 瑙傚療鍙互寰楀嚭 dp[p][j] 鍜?dp[p][j+1] 鐨勮綆楁湁寰堝鐨勯噸鍙?br>鍥犱負(fù) 涓婃鎷夸簡j+1 鍒欏彲浠ユ瘮 dp[p][j] 澶氭嬁 2 涓?nbsp;
鐒跺悗錛岀敱浜庤冭檻j鐨勮寖鍥?搴旇涓?N-i+1
榪欐牱寰楀埌浜嗘渶緇堜唬鐮侊細(xì)
scanf("%d",&N); for(int i=1;i<=N;i++) scanf("%d",coins+i);//{fin>>coins[i]; } sum[0]=0; for(int i=1;i<=N;i++) sum[i]=sum[i-1]+coins[N-i+1]; for(int i=1;i<=N;i++) //鍓?涓?i 涓? for(int j=1;j<= N-i +1;j++){ // 涓?嬈?鎷?浜?j 涓? if(dp[i][j]<dp[i][j-1])dp[i][j]=dp[i][j-1]; if(2*j-1<=i&&dp[i][j]<sum[i]-dp[i-2*j+1][2*j-1]) dp[i][j]=sum[i]-dp[i-2*j+1][2*j-1]; if(2*j<=i&&dp[i][j]<sum[i]-dp[i-2*j][2*j]) dp[i][j]= sum[i]-dp[i-2*j][2*j]; } printf("%d\n",dp[N][1]);
寰堟櫄浜?錛屽厛鍐欒繖涔堝 錛屾湁絀烘妸bronze鐨勫啓浜?/strong>