两道水题
来源:互联网 发布:域名可以用来干什么 编辑:程序博客网 时间:2024/06/12 00:35
POJ 1088 滑雪
一开始行列搞反了 WA了一次
#include <stdio.h>#include <stdlib.h>#include <string.h>#define inf 0x3f3f3f3f#define maxn 205int dp[maxn][maxn], dir[2] = {-1, 1};int map[maxn][maxn];int max(int a, int b){ return a > b ? a : b;}int solve(int x, int y){ if(dp[x][y] != -1) return dp[x][y]; for(int i = 0; i < 2; i++){ if(map[x][y] > map[x][y + dir[i]]) dp[x][y] = max(dp[x][y], 1 + solve(x, y + dir[i])); if(map[x][y] > map[x + dir[i]][y]) dp[x][y] = max(dp[x][y], 1 + solve(x + dir[i], y)); } if(map[x][y] <= map[x-1][y] && map[x][y] <= map[x+1][y] && map[x][y] <= map[x][y-1] && map[x][y] <= map[x][y+1]) dp[x][y] = 1; return dp[x][y];}int main(){ int R, C; memset(map, 0x3f, sizeof(map)); memset(dp, -1, sizeof(dp)); scanf("%d %d", &R, &C); for(int x = 1; x <= R; x++) for(int y = 1; y <= C; y++) scanf("%d", &map[x][y]); int res = 0; for(int x = 1; x <= R; x++) for(int y = 1; y <= C; y++) res = max(res, solve(x, y)); printf("%d\n", res); return 0;}
Dance Dance Revolution
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#define inf 0x3f3f3f3f#define LEN 10000int dp[5][5][LEN], steps[LEN];int min(int a, int b){ return a > b ? b : a;}int cost(int x, int y){ if(x == y) return 1; if((x == 0 || y == 0) && (x + y != 0)) return 2; if(abs(x % 4 - y % 4) == 1) return 3; if(abs(x % 4 - y % 4) == 2) return 4;}int solve(int len, int *step){ dp[0][step[1]][1] = cost(0, step[1]); dp[step[1]][0][1] = cost(0, step[1]); for(int i = 1; i < len; i++){ for(int x = 0; x <= 4; x++){ for(int y = 0; y <= 4; y++){ //move left if(step[i+1] != y) dp[step[i+1]][y][i+1] = min(dp[step[i+1]][y][i+1], cost(x, step[i+1]) + dp[x][y][i]); //move right if(step[i+1] != x) dp[x][step[i+1]][i+1] = min(dp[x][step[i+1]][i+1], cost(y, step[i+1]) + dp[x][y][i]); } } } int ans = inf; for(int i = 0; i < 5; i++){ ans = min( min(dp[i][step[len]][len], dp[step[len]][i][len]), ans); } return ans;}int main(){ int len = 0; while(true){ int i = 1; while(true){ scanf("%d", &steps[i]); if(0 == steps[i]){ len = i - 1; break; } i++; } if(0 == len) break; memset(dp, 0x3f, sizeof(dp)); int ans = solve(len, steps); printf("%d\n", ans); } return 0;}
0 0
- 两道水题
- 鞍山赛区的两道水题
- 牡丹江赛区两道水题A I。
- BestCoder#27两道水题 HDU5162&&5163
- BestCoder#28两道水题 HDU5166&&5167
- 重回HDOJ刷的两道水题
- BestCoder 的两道水题 HDU 4989 4990
- 1163两道水题结合起来的水题
- 关于 中国剩余定理 的两道水题练手
- Scala进阶编程指南
- linux命令
- MySQL:索引工作原理
- 一个最简单的CLI命令行界面实现
- HDU pie (二分查找)
- 两道水题
- 域:一款抽象的射击游戏
- poj 2062 Card Game Cheater(排序+模拟)
- 【CODEFORCES】 B. Dreamoon and Sets
- Redis命令执行全过程
- 深度学习工具箱和Vlfeat库的配置及使用
- 卡塔尼亚中文离线地图App上线
- poj 1308 Is It A Tree?
- (WPF)路由策略