【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][ ...
随机推荐
- Linux替换文件行首的空白字符
使用命令sed.cp.tail.cat 1.拷贝一个任意文件(生产环境切勿操作) cp /etc/profile /tmp 查看文件部分格式 cat /tmp/profile # /etc/profi ...
- docker--build base image
通过dockerfile build一个base image,在上面运行一个c程序 首先 1.创建一个目录. 2.然后创建一个c写的小程序,并且gcc编译好. 3.创建一个Dockerfile FRO ...
- 查看hive版本号
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sheismylife/article/details/33378243 hive没有提供hive - ...
- shell同时输出多行信息
- Linux下Golang Socket编程原理分析与代码实现
在POSIX标准推出后,socket在各大主流OS平台上都得到了很好的支持.而Golang是自带Runtime的跨平台编程语言,Go中提供给开发者的Socket API是建立在操作系统原生Socket ...
- python_异常
异常的概念 程序在运行时,如果 Python 解释器 遇到 到一个错误,会停止程序的执行,并且提示一些错误信息,这就是 异常 程序停止执行并且提示错误信息 这个动作,我们通常称之为:抛出(raise) ...
- springcolud依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- springCloud参考资料
官网: http://spring.io/projects/spring-cloud 各组件说明(中文版):https://springcloud.cc/spring-cloud-netflflix. ...
- jqery基础知识实例(二)
无缝滚动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- Linux中网卡配置/etc/sysconfig/network-script/ifcfg-eth0
网络接口配置文件 [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet #网卡类型 DEVIC ...