【HDUOJ】几道递推DP
就不写题解了。很基础的递推。
HDU2084数塔
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn = ; int dp[maxn][maxn];
int a[maxn][maxn]; int main(){
int T;
cin>>T;
while(T--){
memset(a,,sizeof(a));
memset(dp,,sizeof(dp));
int n;
cin>>n;
for(int i = ; i <= n ;i++){
for(int j = ; j <= i; j++){
cin>>a[i][j];
}
} for(int i = n; i > ; i--){
for(int j = ; j <= n ;j++){
dp[i][j] = max(dp[i+][j] ,dp[i+][j+]) + a[i][j];
}
}
cout<<dp[][]<<endl;
} return ;
}
HDU2018母牛的故事
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2018
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn = ;
int dp[maxn]; void init(){
dp[] = ;
dp[] = ;
dp[] = ;
dp[] = ;
dp[] = ;
for(int i = ; i <= ; i++){
dp[i] = dp[i-] + dp[i-];
}
} int main(){
int n;
init();
while(cin>>n && n){
cout<<dp[n]<<endl;
} return ;
}
HDU2044小蜜蜂的故事
同类型HDU2041
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2044
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
const int maxn = ;
ll fib[maxn]; void init(){
fib[] = ;
fib[] = ;
fib[] = ;
for(int i = ;i <= maxn ;i++){
fib[i] = fib[i-] + fib[i-];
}
} int main(){
init();
int n,m;
int T;
cin>>T;
while(T--){
cin>>n>>m;
cout<<fib[m-n]<<endl;
} return ;
}
HDU2050
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2050
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
const int maxn = ;
ll dp[maxn]; void init(){
dp[] = ;
dp[] = ;
for(int i = ; i <= maxn; i++){
dp[i] = dp[i-] + *(i-) + ;
}
} int main(){
int T;
cin>>T;
int n;
init();
while(T--){
cin>>n;
cout<<dp[n]<<endl;
} return ;
}
【HDUOJ】几道递推DP的更多相关文章
- 递推DP UVA 1366 Martian Mining
题目传送门 /* 题意:抽象一点就是给两个矩阵,重叠的(就是两者选择其一),两种铺路:从右到左和从下到上,中途不能转弯, 到达边界后把沿途路上的权值相加求和使最大 DP:这是道递推题,首先我题目看了老 ...
- 递推DP URAL 1167 Bicolored Horses
题目传送门 题意:k个马棚,n条马,黑马1, 白马0,每个马棚unhappy指数:黑马数*白马数,问最小的unhappy值是多少分析:dp[i][j] 表示第i个马棚放j只马的最小unhappy值,状 ...
- 递推DP URAL 1017 Staircases
题目传送门 /* 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 状态转 ...
- 递推DP URAL 1260 Nudnik Photographer
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- 递推DP URAL 1119 Metro
题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好 ...
- 递推DP 赛码 1005 Game
题目传送门 /* 递推DP:官方题解 令Fi,j代表剩下i个人时,若BrotherK的位置是1,那么位置为j的人是否可能获胜 转移的时候可以枚举当前轮指定的数是什么,那么就可以计算出当前位置j的人在剩 ...
- 递推DP HDOJ 5328 Problem Killer
题目传送门 /* 递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理 判断ai-2, ai-1, ai是否是等差(比)数列,能在O( ...
- hdu1978(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 分析: 递推DP. dp[][]表示可以到达改点的方法数. 刚开始:外循环扫描所有点dp[x][ ...
随机推荐
- 将excle表中得数据生成insert语句插入到数据库中
第一步:输入公式 第二步:拽住右下角得+往下拖拽
- os.walk|图片数据集
该函数的功能:遍历指定文件夹下的所有[路径][文件夹][文件名] ''' os.walk(top[, topdown=True[, onerror=None[, followlinks=False]] ...
- 三、函数 (SUM、MIN、MAX、COUNT、AVG)
第八章 使用数据处理函数 8.1 函数 SQL支持利用函数来处理数据.函数一般是在数据上执行的,给数据的转换和处理提供了方便. 每一个DBMS都有特定的函数.只有少数几个函数被所有主要的DBMS等同的 ...
- 关系型数据的分布式处理系统:Cobar
Cobar简介 Cobar是关系型数据的分布式处理系统,它可以在分布式的环境下像传统数据库一样为您提供海量数据服务. Github:https://github.com/alibaba/cobar 整 ...
- KMP算法及实现
#include<cstdio> #include<cmath> #include<cstring> #include<iostream> #inclu ...
- teb教程1
http://wiki.ros.org/teb_local_planner/Tutorials/Setup%20and%20test%20Optimization 简介:本部分关于teb怎样优化轨迹以 ...
- python3 获取当前路径及os.path.dirname的使用
方法一: import sys,os os.getcwd()#然后就可以看见结果了 方法二: import os os.path.dirname(os.path.realpath('__file__' ...
- 【TJOI2018】教科书般的亵渎
题面 题目描述 小豆喜欢玩游戏,现在他在玩一个游戏遇到这样的场面,每个怪的血量为\(a_i\),且每个怪物血量均不相同,小豆手里有无限张"亵渎".亵渎的效果是对所有的怪造成11点伤 ...
- mysql 中字符串拼接,查询sql语句总结
DELIMITER $$ USE `ld_wpfmgl_sys`$$ DROP PROCEDURE IF EXISTS `code_query`$$ CREATE DEFINER=`root`@`%` ...
- Cesium导出PDF
首先安装 html2Canvas 和 jspdf npm i html2Canvas - S npm i jspdf - S 然后在vue页面引入 import html2Canvas from 'h ...