[HDU 1422]重温世界杯(DP)
来源:互联网 发布:从哪里招聘美工 编辑:程序博客网 时间:2024/06/06 13:25
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1422
思路:DP,状态f[i]保存到达第i个城市口袋里的钱和最多能访问到的城市个数,用序列型DP的思想处理,按照终点进行DP即可
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#define MAXN 200010using namespace std;struct node{ int num,v; //v=到达第i个城市时口袋里的钱,num=到达第i个城市时最多访问的城市个数}f[MAXN];int cnt[MAXN]; //cnt[i]=在第i个城市时多得到的钱int main(){ int n; while(scanf("%d",&n)!=EOF&&n) { memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) { int money,cost; scanf("%d%d",&money,&cost); cnt[i]=money-cost; cnt[i+n]=money-cost; } f[1].v=cnt[1]; if(f[1].v>=0) f[1].num=1; else f[1].num=0; if(n>=2) { for(int i=2;i<=2*n;i++) { if(f[i-1].v>=0) { if(f[i-1].v+cnt[i]>=0) { f[i].v=f[i-1].v+cnt[i]; f[i].num=f[i-1].num+1; if(f[i].num>=n) break; } else { f[i].v=cnt[i]; if(cnt[i]>=0) f[i].num=1; else f[i].num=0; } } else { f[i].v=cnt[i]; if(cnt[i]>=0) f[i].num=1; else f[i].num=0; } } } int ans=0; for(int i=1;i<=2*n;i++) if(ans<f[i].num) ans=f[i].num; printf("%d\n",ans); } return 0;}
0 0
- [HDU 1422]重温世界杯(DP)
- hdu---1422重温世界杯(DP)
- hdu 1422 重温世界杯 dp
- 【DP|水】HDU-1422 重温世界杯
- hdu 1422 重温世界杯(dp)
- 【HDU 1422】重温世界杯(DP)
- Hdu 1422 - 重温世界杯
- hdu 1422 重温世界杯
- HDU 1422 重温世界杯
- HDU 1422 重温世界杯
- HDU - 1422 重温世界杯
- HDU 1422 重温世界杯
- hdu 1422 重温世界杯
- hdu 1422 重温世界杯
- hdu 1422 重温世界杯
- hdu 1422 重温世界杯
- HDU 1422:重温世界杯
- HDU 1422 重温世界杯
- Django1.7学习笔记(四)
- 深入理解java异常处理机制
- 第一周项目三 程序的多文件组织
- EJB和Web容器中的资源或组件是如何查找的?
- VIM Usage
- [HDU 1422]重温世界杯(DP)
- 第11周项目1-函数版星号图(2)
- 存储过程里的序列报错Error: PLS-00302: component 'SEQUENCE_NAME' must be declared
- copy redis data from server A to server B
- 删除数据----DELETE AND TRUNCATE TABLE
- C4.5算法详解(至今见过写的最好的算法详解)
- 我遇到的java问题
- ListView中getView的原理+如何在ListView中放置多个item
- 第十一周项目1 (3)函数版小星星(ABC+++++)