| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我要晕死了,无语了,该啊该啊,第一次写dp,被边界弄死了#include<iostream>
#include <cstring>
using namespace std;
const int INF=0x7fffffff-1000;
int table[105][105],dp[105][105]; //dp[i][j]表示把i束花放入前j个花瓶的最大价值
int main()
{
int F,V;
while(cin>>F>>V)
{
for(int i=0;i<105;++i)
for(int j=0;j<105;++j)
dp[i][j]=-INF;
for(int i=1;i<=F;++i)
for(int j=1;j<=V;++j)
cin>>table[i][j];
for(int j=1;j<=V;++j)
{
for(int i=1;i<=min(j,F);++i)
{
int t=dp[i-1][j-1]==-INF?0:dp[i-1][j-1];
dp[i][j]=max(dp[i][j-1],t+table[i][j]);
}
}
cout<<dp[F][V]<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator