• POJ 1157


    简单的dp。状态定义好就迎刃而解,令(dp(i, j))为第(i)种花必须在第j个花瓶,且满足条件的最大aesthetic value

    状态转移方程也很好想,估计了下时间复杂度发现没问题,就着手实现了

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    using namespace std;
    
    const int maxf= 105;
    const int maxv= 105;
    const int INF= 0x3f3f3f3f;
    
    int fv[maxf][maxv], dv[maxf][maxv];
    int f, v;
    
    int main(int argc, char const *argv[])
    {
    	scanf("%d %d", &f, &v);
    
    	for (int i= 1; i<= f; ++i){
    		for (int j= 1; j<= v; ++j){
    			scanf("%d", fv[i]+j);
    		}
    	}
    	memset(dv, 0xc0, sizeof(dv));
    
    	for (int i= 0; i<= v; ++i){
    		dv[0][i]= 0;
    	}
    	for (int i= 1; i<= f; ++i){
    		dv[i][i]= dv[i-1][i-1]+fv[i][i];
    	}
    
    	int ud= v-f;
    	for (int d= 1; d<= ud; ++d){
    		for (int i= 1, j= i+d; j<= v; ++i, ++j){
    			int tv= dv[i][j];
    			for (int k= i-1; k< j; ++k){
    				tv= max(tv, dv[i-1][k]);
    			}
    			dv[i][j]= tv+fv[i][j];
    		}
    	}
    
    	int ans= -INF;
    	for (int i= f; i<= v; ++i){
    		ans= max(ans, dv[f][i]);
    	}
    
    	printf("%d
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    假期十一
    假期十
    假期九
    假期八
    假期七
    假期六
    假期五
    假期四
    2020.02.11
    2020.02.10
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14706795.html
Copyright © 2020-2023  润新知