nyist 1204 魔法少女
来源:互联网 发布:淘宝客户端电脑版 编辑:程序博客网 时间:2024/06/12 01:25
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1204
思路:dp[i]从dp[i-1]转移,这个转移就枚举了不使用魔法的过程,这个思路挺巧妙的,还有就是刚开始的特判也挺巧妙的
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long LL;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int dp[10010];int h[10010];int main(){ int n; while(scanf("%d",&n) != EOF) { memset(dp,0,sizeof(dp)); for(int i=1; i<=n; i++) scanf("%d",&h[i]); if(n < 3) { printf("0\n"); continue; } if(n == 3) { sort(h+1,h+n+1); printf("%d\n",h[1]); continue; } if(n > 3) { dp[1] = h[1]; dp[2] = h[2]; h[n+1] = 0; for(int i=3; i<=n+1; i++) dp[i] = min(dp[i-1],min(dp[i-2],dp[i-3])) + h[i]; printf("%d\n",dp[n+1]); } } return 0;}
0 0
- nyist 1204 魔法少女
- nyoj 1204魔法少女
- 南阳OJ 1204 魔法少女
- 魔法少女
- 魔法少女
- 魔法少女
- 魔法少女
- NYOJ 1204 魔法少女 简单DP
- nbut_1010 魔法少女 dp
- 拯救魔法少女
- BZOJ4399: 魔法少女LJJ
- 4399: 魔法少女LJJ
- 【NOJ】[1010] 魔法少女
- nyoj 魔法少女(简单dp)
- nyoj1204 魔法少女 线性DP
- BZOJ4399: 魔法少女LJJ treap
- BZOJ 4399: 魔法少女LJJ
- NYOJ1204-魔法少女(动态规划)
- Java泄露及造成内存泄露的原因
- 借助链表解决猴子选大王问题(约瑟夫环问题)
- codeforces-597C-Subsequences【树状数组】
- 判断一棵树是否是二叉查找树
- IOS学习之——导航控制器 UINavigationController
- nyist 1204 魔法少女
- 浙大校长吴朝晖在2016年研究生毕业典礼上的讲话:海纳江河传承求是 开物前民笃行创新
- 台大机器学习笔记(10-11)——Linear Models for Classification&Stochastic Gradient Descent
- mysql启动和关闭外键约束的方法
- centos7 防火墙 错误 (坑)
- ALV中将某一字段做为按钮
- 【LeetCode】58. Length of Last Word
- Python pip使用小结
- WebRTC代码走读(八):代码目录结构