C++动态规划
数塔:
#include <iostream>
using namespace std;
int a[1000][1000];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<i+1;j++){
cin>>a[i][j];
}
}
for(int i=n-2;i>=0;i--){
for(int j=0;j<i+1;j++){
a[i][j]+=a[i+1][j]>a[i+1][j+1]?a[i+1][j]: a[i+1][j+1];
}
}
cout<<a[0][0];
}
最大连续子序列
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000];
int main(){
int n;int mx=0;
while(1){
mx=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
a[i]+=a[i-1]>0?a[i-1]:0;
if(a[i]>mx) mx=a[i];
}
cout<<mx;
}
}
馅饼(仿数塔):
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[13][1000];int x,y;
int main(){
int n;int mx=0;
while(1){
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
a[x+1][y]+=1;
if(y>mx) mx=y;
}
for(int i=mx-1;i>=0;i--){
for(int j=1;j<12;j++){
a[j][i]+=max(a[j-1][i+1],max(a[j][i+1],a[j+1][i+1]));
}
}
cout<<a[6][0];
}
}
C++动态规划的更多相关文章
- 增强学习(三)----- MDP的动态规划解法
上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...
- 简单动态规划-LeetCode198
题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- 动态规划之最长公共子序列(LCS)
转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...
- C#动态规划查找两个字符串最大子串
//动态规划查找两个字符串最大子串 public static string lcs(string word1, string word2) { ...
- C#递归、动态规划计算斐波那契数列
//递归 public static long recurFib(int num) { if (num < 2) ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
[BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
随机推荐
- python爬虫入门(1)----- requests
介绍 requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 基本使用 requests.get("http://www.baidu.com") ...
- django-rest-framework-源码解析003-视图家族和路由(APIView/GenericAPIView/mixins/generics/viewsets)
视图家族 视图家族在rest_framework源码位置和学习曲线为: rest_framework.views: 基本视图(APIView) rest_framework.generics: 工具视 ...
- Windows10系统,截图黑屏,怎么办?
问题:Windows10系统,截图黑屏,怎么办? 图片描述: 原因:也许有 媒体播放软件和系统(或者正在使用的截图软件)起了冲突. 我就开了个这个软件,就完蛋了. 导致了 系统自带的 这两个截图 ...
- vue+axios+springboot文件下载
//前台代码 <el-button size="medium" type="primary" @click="downloadFile" ...
- Java对象公约
灵魂static关键字 Java规定:方法只能由对象来调用. 换句话来说,在面向对象的思维下,方法与对象存在一种强耦合. static作用:即使没有初始化对象,也可以调用方法.(类比到属性上同样如此) ...
- 查询MySQL数据库中表结构
什么是表结构?表结构就是定义数据表文件名,确定数据表包含哪些字段,各字段的字段名.字段类型.及宽度,并将这些数据输入到计算机当中. 查询方法:以表‘employees’为例子 1.describe(d ...
- Raid0,1,5,10,50
raid0 就是把多个硬盘合并成1个逻辑盘使用,数据读写时对各硬盘同时操作,不同硬盘写入不同数据,速度快. **最少需要2块硬盘 raid1 同时对2个硬盘读写(同样的数据).强调数据的安全性.损坏一 ...
- PHP strrchr() 函数
实例 搜索 "world" 在字符串中的位置,并返回从该位置到字符串结尾的所有字符: <?php高佣联盟 www.cgewang.comecho strrchr(" ...
- PHP str_shuffle() 函数
实例 随机地打乱字符串中的所有字符: <?php高佣联盟 www.cgewang.comecho str_shuffle("Hello World");?> 定义和用法 ...
- C#后台实现在Grid标签中动态新增CheckBox标签(WPF中)
页面代码 <Grid Margin="45,0,10,0" > <Grid.RowDefinitions> <RowDefinition Height ...