HihoCoder1037數字三角形(dp題)
来源:互联网 发布:python编程入门 第3版 编辑:程序博客网 时间:2024/04/29 09:22
oop 運動動態規劃思想
#include<iostream>#include <string.h>using namespace std;const int m = 350;class Angel{public: Angel(); int intput(); int solve(); const int getResult() const;private: int n; int a[m][m]; int sum; };Angel::Angel(){ int sum =0; this->n = 0; this->a[m][m] = {0};}int Angel::intput(){ cin>>this->n; for(int i =0;i < n; i++) { for (int j = 0;j<= i; j++) cin>>this->a[i][j]; } return 0;}int Angel::solve(){ for(int i =1;i < n; i++) { for (int j = 0;j<= i; j++) { if (j == 0) { a[i][j]=a[i-1][j]+a[i][j]; } else if (j == i) { a[i][j]=a[i-1][j-1]+a[i][j]; } else { a[i][j] =max(a[i-1][j],a[i-1][j-1])+a[i][j]; } } } for (int i = 0; i <n ; i++) { if (a[n-1][i]>sum) { sum = a[n-1][i]; } } return 0;}const int Angel::getResult() const{ return this->sum;}template <typename T>T max (T a,T b){ return a>b? a:b;}int main(int argc , const char * argv[]){ Angel * a = new Angel(); a->intput(); a->solve(); cout<<a->getResult(); }
1 0
- HihoCoder1037數字三角形(dp題)
- hihocoder1037 数字三角形
- [hihocoder1037]数字三角形
- hihocoder1037(记忆化搜索)
- hdu 1249 三角形 (DP)
- 数字三角形问题(DP)
- 算法:数字三角形(DP)
- POJ 1163 数字三角形问题(DP)
- NEFU 17 数字三角形(简单dp)
- #1037 : 数字三角形(基础DP)
- hihoCoder#1037 : 数字三角形(DP)
- hihoCoder 1037 数字三角形(基础dp)
- hiho1037 数字三角形 (数塔 dp)
- 数字三角形(迷宫奖卷)dp
- 【dp】数字三角形问题
- 【DP】数字三角形4
- 数字三角形DP
- 数字三角形 DP
- 啤酒和饮料
- Mac OS X中配置Apache
- 设计模式--基础学习总结
- 用最简单的例子实现jQuery图片即时上传
- ceph存储 ceph集群消息处理
- HihoCoder1037數字三角形(dp題)
- 百度大数据质量保障方案探索
- 字母图形
- Android之Adapter优化
- android:inputType常用取值
- Android编程:定时器和Handler的使用
- iOS调起打电话
- Hibernate @Embeddable注解
- 将网页标题的乱码中文汉化的方法