skiing 暴力搜索 + 动态规划


我的代码上去就是 直接纯粹的 暴力 . 居然没有超时 200ms 可能数据比较小 一会在优化
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
using namespace std;
int n,m,a[][],visited[][],b[][]={,-,,,-,,,},minn;
void DFS(int y,int x,int now)
{
for(int i=;i<;i++)
{
int x1=x+b[i][],y1=y+b[i][];
if(x1>=&&x1<m&&y1>=&&y1<n&&!visited[y1][x1]&&a[y1][x1]<a[y][x])
{
now++;
if(now>minn)
minn=now;
visited[y1][x1]=;
DFS(y1,x1,now);
visited[y1][x1]=;
now--;
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(int i=;i<n;i++)
for(int j=;j<n;j++)
scanf("%d",&a[i][j]);
minn=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
memset(visited,,sizeof(visited));
visited[i][j]=;
DFS(i,j,);
}
printf("%d\n",minn);
}
}
下面附上 动态规划的 解法 这个 动态规划 是一种 人人为我 , 的思想 , 先根据 高度进行从小到的 排序 然后 然后从 第二小的 开始 检查 周围是否 有比他 还小的 , 如果有的话 , 将周围的 +1 个 自身相比 取最大值 , 废话少说 放码过来
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
using namespace std;
struct node
{
int x,y,h;
}a[];
bool cmp(node example_a,node example_b)
{
return example_a.h<example_b.h;
}
int b[][]={,-,,,-,,,},c[][],d[][];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int total=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
d[i][j]=;
scanf("%d",&c[i][j]);
a[total].h=c[i][j],a[total].x=j,a[total].y=i; // 将所有的 长度 默认为 1
total++;
}
}
sort(a,a+total,cmp);
int maxn=;
for(int i=;i<total;i++) // 从 第二小的 开始 当周围 有 比他小 的 就 +1
{
for(int j=;j<;j++)
{
if(a[i].x+b[j][]>=&&a[i].x+b[j][]<m&&a[i].y+b[j][]>=&&a[i].y+b[j][]<n&&c[a[i].y][a[i].x]>c[a[i].y+b[j][]][a[i].x+b[j][]])
{
d[a[i].y][a[i].x]=max(d[a[i].y][a[i].x],d[a[i].y+b[j][]][a[i].x+b[j][]]+);
maxn=max(maxn,d[a[i].y][a[i].x]);
}
}
}
printf("%d\n",maxn);
}
return ;
}
skiing 暴力搜索 + 动态规划的更多相关文章
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- 区间Dp 暴力枚举+动态规划 Hdu1081
F - 最大子矩形 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status Des ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- 随手练——洛谷-P1151(枚举与暴力搜索)
枚举 #include <iostream> using namespace std; int main() { ; cin >> k; ; i < ; i++) { ) ...
- 枚举进程——暴力搜索内存(Ring0)
上面说过了隐藏进程,这篇博客我们就简单描述一下暴力搜索进程. 一个进程要运行,必然会加载到内存中,断链隐藏进程只是把EPROCESS从链表上摘除了,但它还是驻留在内存中的.这样我们就有了找到它的方法. ...
- [luogu 1092] 虫食算 (暴力搜索剪枝)
传送门 Description Input 包含四行. 第一行有一个正整数 (N≤26). 后面的三行,每行有一个由大写字母组成的字符串,分别代表两个加数以及和.这3个字符串左右两端都没有空格,从高位 ...
- HDU 3131 One…Two…Five! (暴力搜索)
题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...
- 吴裕雄 python 机器学习——模型选择参数优化暴力搜索寻优GridSearchCV模型
import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...
随机推荐
- journals in Fluid Dynamics
annual review of fluid mechanicsjournal of fluid mechanicsphysics of fluidjournal of flow and struct ...
- [spoj1182][Sorted Bit Sequence] (数位dp)
Description Let's consider the 32 bit representation of all integers i from m up to n inclusive (m ≤ ...
- 【Codeforces 442B】Andrey and Problem
[链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...
- 解决win10磁盘占用过大的问题(亲测有效)
问题:打开任务管理器,经常会发现磁盘占用95%以上,电脑很卡,下面是解决方案 方法: 1.关闭家庭组. (1)搜索服务,找到“HomeGroupListener”服务,右键单击“属性”.在弹出属性界面 ...
- 什么是Spring Boot简介
1.什么是spring boot 简单的说,spring boot就是整合了很多优秀的框架,不用我们自己手动的去写一堆xml配置然后进行配置. 从本质上来说,Spring Boot就是Spring,它 ...
- 最小生成树 D - Constructing Roads
There are N villages, which are numbered from 1 to N, and you should build some roads such that ever ...
- 在docker上安装运行mysql实例
ps:实验环境是:CentOS Linux release 7.3 64位1.获取mysql镜像从docker hub的仓库中拉取mysql镜像docker pull mysql查看镜像docker ...
- Angularjs中添加HighCharts
一. 添加基本配置 1. 添加指令 angular.module('newApp') .directive('dpHighchart', ['$rootScope', function($rootSc ...
- 【CV论文阅读】 Fast RCNN + SGD笔记
Fast RCNN的结构: 先从这幅图解释FAST RCNN的结构.首先,FAST RCNN的输入是包含两部分,image以及region proposal(在论文中叫做region of inter ...
- raywenderlich.com的Swift编程风格指南
翻译自:https://github.com/raywenderlich/swift-style-guide 这个风格指南可能和你从其它地方看到的不同,我们的焦点主要集中在互联网和文章上的可读性.创建 ...