虽然之前学过一点点,但是还是不会------现在好好跟着白书1.4节学一下——————

(1)数字三角形

d(i,j) = max(d(i+1,j),d(i+1,j+1)) + a[i][j]

hdu 2084

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int d[][],a[][]; int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
memset(d,,sizeof(d));
for(int i = ;i<=n;i++)
for(int j = ;j<=i;j++) scanf("%d",&a[i][j]); for(int i = n;i>=;i--){
for(int j = ;j<=i;j++)
d[i][j] = max(d[i+][j],d[i+][j+]) + a[i][j];
}
printf("%d\n",d[][]);
}
return ;
}

(2)嵌套矩形

把图先建出来,然后d(i) = max(d(j) + 1)

nyoj 16

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int g[][];
int d[];
int n; struct node{
int x,y;
}a[maxn]; int dp(int i){
int& ans = d[i];
if(ans > ) return ans;
ans = ;
for(int j = ;j <= n;j++)
if(g[i][j]) ans = max(ans,dp(j) + ); return ans;
} int work(){
int res = -;
for(int i = ;i <= n;i++) res = max(res,dp(i));
return res;
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i = ;i <= n;i++) scanf("%d %d",&a[i].x,&a[i].y);
memset(g,,sizeof(g));
memset(d,,sizeof(d)); for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
if((a[i].x > a[j].x && a[i].y > a[j].y) || (a[i].x > a[j].y && a[i].y > a[j].x ))
g[i][j] = ;
}
} printf("%d\n",work());
}
return ;
}

最新文章

  1. 原生ajax基础
  2. MapReduce实现WordCount
  3. Java与mysql数据库编程中遇见“Before start of result set at com.mysql.jdbc.SQLError.createSQLException” 的解决办法
  4. ORACLE 数据的逻辑组成
  5. tableView 显示区域偏移
  6. 关于session更新的问题
  7. 对于JavaScript对象的prototype和__proto__的理解
  8. HashMap的使用方法及注意事项
  9. javascript中,数组常用的方法有哪些?
  10. 对&quot;一维最大子数组和&quot;问题的思考
  11. System.Text.RegularExpressions.Regex
  12. 前端综合学习笔记---异步、ES6/7、Module、Promise同步 vs 异步
  13. IntelliJ IDEA下Cannot resolve symbol XXX的解决方法
  14. Net Core平台灵活简单的日志记录框架NLog+Mysql组合初体验
  15. ionic3 出现莫名广告
  16. 关于h5使用bpmn.js
  17. JSP内置对象——Exception对象
  18. 加速cin的技巧
  19. python day09作业答案
  20. java向数据库插入N条数据

热门文章

  1. Lazy Stored Properties--无括号时为匿名函数
  2. Java中数组的定义方式
  3. C# word生成html
  4. Php+Redis队列原理
  5. kali2018.2安装配置OpenVAS-9及错误处置
  6. Python编码显示中文乱码
  7. Untiy中的数据平滑处理
  8. [置顶] 大数据架构hadoop
  9. Warning: The following processes: -cmd.exe -java.exe are locking the following directory:
  10. css 超出宽度出现省略号