数塔
2016-04-21 18:53
295 查看
http://vjudge.net/contest/view.action?cid=50286#problem/I数塔问题:自底向上地推 dp[1][1]就是答案状态转移方程为dp[i][j]=mp[i][j]+max(dp[i+1][j+1],dp[i+1][j])。dp[i][j]表示以i j为起点走到最底层所得到的最大值。
#include<iostream> #include<cstring> #include<algorithm> #include<cstdlib> #include<vector> #include<cmath> #include<stdlib.h> #include<iomanip> #include<list> #include<deque> #include<map> #include <stdio.h> #include <queue> #define maxn 10000+5 #define ull unsigned long long #define ll long long #define reP(i,n) for(i=1;i<=n;i++) #define rep(i,n) for(i=0;i<n;i++) #define cle(a) memset(a,0,sizeof(a)) #define mod 90001 #define PI 3.141592657 const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } int mp[103][103],dp[103][103]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int t,n,i,j; cin>>t; while(t--) { cle(mp);cle(dp); cin>>n; for(i=1;i<=n;i++) for( j=1;j<=i;j++) cin>>mp[i][j]; for(int j=1;j<=n;j++) dp[n][j]=mp[n][j]; ///初始化底边 for(int i=n-1;i>=1;i--)///白书例题 for(int j=1;j<=i;j++) { dp[i][j]=mp[i][j]+max(dp[i+1][j+1],dp[i+1][j]); } cout<<dp[1][1]<<endl; } return 0; }
相关文章推荐
- 命运
- HDU 2602 Bone Collector
- HDU 4706 Children\'s Day
- HDU 1551 Cable master
- HDU 4708 Rotation Lock Puzzle
- Difference Between Primes----素数筛选
- HDU 1669 & poj 3122 pie
- 测试作业
- Redis数据库安装部署
- 编译ffmpeg with gpu
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 【尺取】POJ 3320
- do-until随机求十个数的和
- Objective-C学习笔记(三)——用Objective-C编写第一个程序:Hello,World!
- Codeforces Round #260 (Div. 2) 第一题A. Laptops
- HDU1789 Doing Homework again(贪心)
- 【转载】HDU 2844.Coins(多重背包转01背包)
- CodeForces - 552A Vanya and Table (水)
- 背包问题模版
- Coderforces练习---水题