poj Apple Catching 動態規劃

2021-06-23 01:10:59 字數 609 閱讀 3644

description

input

* line 1: two space separated integers: t and w

output

sample input

7 221

1221

1

sample output

6

hint

input details:

output details:

題意大致是有兩棵蘋果樹編號為1,2,每分鐘會有乙個蘋果從其中一棵樹掉下,bessie可以從一棵樹移到另一棵樹那裡接蘋果,但是總的次數不能超過w次,一共t個單位時間,問

bessie最多可以吃掉多少蘋果?

#include#include#include#includeusing namespace std;

int main()

memset(dp,0,sizeof(dp));//初始化dp.

for(i=1;i<=t;i++)

}printf("%d\n",dp[t][w]);

}return 0;

}

Prince and Princess 動態規劃

題目大意 求兩個序列的最長子序列 include include include includeusing namespace std int n,p,q const int maxn 250 250 int num1 maxn int hash maxn stack maxn int main i...

Colored Rectangles 動態規劃

題意 三種木棍,分別有 r對 g對 b對兩種不同木棍對可以弄移乙個矩形,要求矩形面積總和最大 思路 看題面,這種幾個變數互相影響並且最終目標固定的題目感覺就要用dp,而且資料比較小應該就是能用三維dp,雖然我比賽時沒做出來,但是我想的挺明白的,狀態轉移就是dp i j k max dp i 1 j ...

hdu1513 Palindrome 動態規劃

求讓乙個字串變為回文串所需最少插入字元數 定義狀態dp i j 表示從左到右i個字元,從右到左j個字元,要讓他們回文需要插入多少字元 顯然,a i a j 時,dp i j d p i 1 j 1 a i a j 時,就需要插入乙個字元,因此dp i j m in d p i 1 j dp i j ...