首页 > TAG信息列表 > 3186
POJ 3186
水题,思路很简单,不过这里有一个另一思路,也蛮有启发性的(关于状态定义) #include <iostream> #include <algorithm> #include <string> #include <vector> #include <cstdio> #include <cstring> using namespace std; const int maxn = 2005; int v[maxn]; int dp[maTreats for the Cows POJ - 3186 dp 区间dp
//dp[i][j]表示第i次从左边取,第j次从右边取的价值,所以我们可以得到状态方程 //dp[i][j]=max(dp[i-1][j]+(i+j)*a[i],dp[i][j-1]+(i+j)*a[n-j+1]) (i > 0 && j > 0 ) //dp[i][0]=dp[i-1][0]+i*a[i],dp[0][i] dp[0][i-1]+i*a[n-i+1]; #include<cstdio> #include<cmath> #include&POJ 3186
题意略。 思路:有一点区间dp的意思。 我令dp[ i ][ j ]表示:区间[1 , i]和区间[j , N]按某种顺序插值排好,所能获得的最大值。 状态转移方程:dp[ i ][ j ] = max(dp[i - 1][ j ] + v[ i ] * (i + N - j + 1) , dp[ i ][ j + 1 ] + v[ j ] * (i + N - j + 1))。 代码如下: #include<iostPOJ - 3186 Treats for the Cows(dp)
FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time. The treats are interesting for many reasons