poj 1157 (DP)
来源:互联网 发布:计划网络图软件 编辑:程序博客网 时间:2024/06/07 19:16
f [ i ] [ j ] = for ( k = i ,k < j ) max ( f [ i ] [ j ], maxvaule [ i - 1 ] [ k ] + value [ i ] [ j ] ; 在最后扫描数组最后一行可以得到最佳结果
代码如下:
#include<iostream>#include<cstring>using namespace std;int flower,vase;int aesthetic[105][105];int maxaes[105][105];/**表示在第i个花放第j个位置的最大的美观程度*/int main(){ while ( cin >> flower >> vase ) { for ( int i = 0; i < flower; i++ ) { for ( int j = 0; j < vase; j++ ) { cin >> aesthetic[i][j]; } } for ( int i = 0; i < flower; i++ ) { for ( int j = i; j < vase; j++ ) { if ( i == 0) maxaes[i][j] = aesthetic[i][j];/**如果是第一个花的话就是输入的美观值*/ else { for ( int k = i - 1; k < j; k++ ) { if ( maxaes[i][j] < maxaes[ i - 1 ][ k ] + aesthetic[i][j] )/**可以采用01滚动,可以节约空间*/ maxaes[i][j] = maxaes[ i - 1 ][ k ] + aesthetic[i][j]; } } } } int ans = -10000; for ( int i = vase - flower; i < vase; i++ ) { if ( ans < maxaes[ flower - 1 ][ i ] )/**找出插入最后一朵花的最大值*/ ans = maxaes[ flower - 1 ][ i ]; } cout << ans << endl; }}
0 0
- poj 1157 (DP)
- POJ 1157(DP ,数塔问题)
- DP <裸> POJ 1157
- poj 1157 DP
- poj 1157 DP
- poj 1157 dp
- poj 1157 dp
- poj 1157 dp
- POJ 1157 dp
- poj 1157 dp
- poj 1160(dp)
- Poj 2229(dp)
- Poj 2385 (dp)
- Poj 3616 (dp)
- Poj 3280(dp)
- Poj 2392(dp)
- Poj 1631(dp)
- poj 3267(dp)
- 周期串
- 技术搜索记录集1
- ARC下dealloc过程及.cxx_destruct的探究
- LeetCode OJ - Search a 2D Matrix
- AXIS2部署WebService实战
- poj 1157 (DP)
- LoadRunner测试接口性能
- insight-vmi 编译中的问题
- 判断点或矩形在某个区域内和点或矩形针对于父视图的坐标转换
- 网络接口的检测
- C++ Primer Plus的若干收获--(三)
- 如何用google translate API接口
- continue,break,return用法的区别
- 编程算法 - 最好牛线(Best Cow Line) 代码(C)