标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 672 Accepted Submission(s): 302
dp[x][y][v]=mx(dp[x-1][y][v],dp[x][y-1][v],dp[x-1][y][v-cost]+value,dp[x][y-1][v-cost]+value);
1 /************************************************************************* 2 > File Name: code/bc/#42/C.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月01日 星期六 10时52分24秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #define y0 abc111qqz 21 #define y1 hust111qqz 22 #define yn hez111qqz 23 #define j1 cute111qqz 24 #define tm crazy111qqz 25 #define lr dying111qqz 26 using namespace std; 27 #define REP(i, n) for (int i=0;i<int(n);++i) 28 typedef long long LL; 29 typedef unsigned long long ULL; 30 const int inf = 0x7fffffff; 31 const int N=1E2+5; 32 int a[N][N]; 33 int n,m,k; 34 int dp[N][N][N]; 35 36 int mx(int x1,int x2,int x3,int x4) 37 { 38 int res = -1; 39 if (x1>res) res = x1; 40 if (x2>res) res = x2; 41 if (x3>res) res = x3; 42 if (x4>res) res = x4; 43 return res; 44 } 45 void solve (int x,int y,int cost, int value) 46 { 47 for ( int v = k ; v >= cost ; v--) 48 { 49 dp[x][y][v]=mx(dp[x-1][y][v],dp[x][y-1][v],dp[x-1][y][v-cost]+value,dp[x][y-1][v-cost]+value); 50 } 51 } 52 int main() 53 { 54 while (scanf("%d %d %d",&n,&m,&k)!=EOF) 55 { 56 for ( int i = 1 ; i <= n ; i++ ) 57 { 58 for ( int j = 1; j <= m ; j++ ) 59 { 60 scanf("%d",&a[i][j]); 61 } 62 } 63 memset(dp,0,sizeof(dp)); 64 for ( int i = 1 ; i <= n ; i++ ) 65 { 66 for ( int j = 1 ; j <= m ; j++ ) 67 { 68 solve(i,j,a[i][j],a[i][j]); 69 } 70 } 71 int ans = -1; 72 for ( int i = 1 ; i <= k ; i++) 73 { 74 ans = max (ans,dp[n][m][i]); 75 } 76 cout<<ans<<endl; 77 } 78 79 return 0; 80 }
hdu 5234 (bc #42 C)Happy birthday(dp)
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4693854.html