HDU 1087

Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N 
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.

 
Output
For each case, print the maximum according to rules, and one line one case.
 
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
 
反思:dp数组的初始话问题,初始化之前要动脑子过一下,这题因为初始化错了好几次;
 //思路很简单的一道题目,但是wa好几次,
 //原因是在准备状态转移的时候,dp[i](到i的最大上升和)的初始化问题,
 //原本直接初始化为0,赋值第一项,以为和打表一样直接递推就能算出所有项,
 //但是应该初始化为a[i],这种题目和打表那种不同,这个每一项都可能是起点。
 #include <iostream>
 #include <cstring>
 #include <cstdio>
 using namespace std;

 int main()
 {
     //freopen("in.txt", "r", stdin);
     ],dp[];
     while(cin>>n,n)
     {
         ; i<n; i++)
             cin>>a[i];

         //memset(dp, 0, sizeof(dp));
         dp[]=a[];

         ];
         ; i<n; i++)
         {
             dp[i]=a[i];  //错解就是没有这个,直接memset的
             ; j<i; j++)
                 if(a[j]<a[i])
                 {
                     dp[i]=max(dp[i], dp[j]+a[i]);
                 }
             ans=max(ans, dp[i]);
         }
         cout<<ans<<endl;

     }
     ;
 }

HDU 1260 卖票的

Problem Description
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
 
Input
There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
 
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
 
Sample Input
2
2
20 25
40
1
8
题解:状态转移式,写出前2项打表即可,注意最后的输出(又wa)
 #include <iostream>
 #include <cstring>
 #include <cstdio>
 using namespace std;

 ;

 int main ()
 {
     //freopen("in.txt", "r", stdin);
     int T;  cin>>T;
     while(T--)
     {
         }, b[maxn]={}, dp[maxn]={};
         int n; cin>>n;
         ; i<=n; i++)
             cin>>a[i];
         ; i<=n; i++)
             cin>>b[i];

         dp[]=a[], dp[]=min(a[]+a[], b[]);
         ; i<=n; i++)
             dp[i]=min(dp[i-]+a[i], dp[i-]+b[i]);

         +;
         /;
         ;
         )
             printf(, m, s);
         else
             printf("%02d:%02d:%02d am\n", h, m, s);

     }
     ;
 }

DP入门水题集的更多相关文章

  1. DP+贪心水题合集_C++

    本文含有原创题,涉及版权利益问题,严禁转载,违者追究法律责任 本次是最后一篇免费的考试题解,以后的考试题目以及题解将会以付费的方式阅读,题目质量可以拿本次作为参考 本来半个月前就已经搞得差不多了,然后 ...

  2. 【省选水题集Day1】一起来AK水题吧! 题解(更新到B)

    题目:http://www.cnblogs.com/ljc20020730/p/6937936.html 水题A:[AHOI2001]质数和分解 安徽省选OI原题!简单Dp. 一看就是完全背包求方案数 ...

  3. wyh的dp入门刷题笔记

    0: 靠前感觉之前dp抄题解都是抄的题解,自己从没有真正理解过dp.wyh下了很大决心从头学dp,于是便有了这篇文章. 1.背包 前四讲01背包&多重背包&完全背包(混合背包) :樱花 ...

  4. 【省选水题集Day1】一起来AK水题吧! 题目(更新到B)

    题解:http://www.cnblogs.com/ljc20020730/p/6937954.html 水题A: [AHOI2001]质数和分解 题目网址: https://www.luogu.or ...

  5. 【专业找水题】状压dp最水题,没有之一

    题目链接 现在代码能力没上升,倒是越来越会找水题了(比例题还水的裸题你值得拥有) 这网站不是针对竞赛的,所以时空限制都很宽松 然后就让我水过去了 对于每个点,包括自己的前m个元素是否取都是一种状态,所 ...

  6. hdu 4540 威威猫系列故事——打地鼠 dp小水题

    威威猫系列故事——打地鼠 Time Limit: 300/100 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  7. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

  8. 状压dp入门第一题 poj3254

    题目链接 http://poj.org/problem?id=3254 转自http://blog.csdn.net/harrypoirot/article/details/23163485 #inc ...

  9. 区间DP入门题目合集

      区间DP主要思想是先在小区间取得最优解,然后小区间合并时更新大区间的最优解.       基本代码: //mst(dp,0) 初始化DP数组 ;i<=n;i++) { dp[i][i]=初始 ...

随机推荐

  1. pytorch入门与实践-2.2-CIFAR10分类网络

    1--数据载入 |----流程: DataSet->DataLoader->调用DataLoader |----DataLoader迭代器读不到数据,无报错,一直卡住的显现: DataLo ...

  2. 实体框架—Entity Framework

    简称EF,是微软以ADO.NET为基础所发展出来的对象关系对应(ORM)解决方案. EF就是用来处理数据的,与数据库打交道.但是底层还是用到了ADO.NET的那一套东西. 为什么叫对象关系对应解决方案 ...

  3. git diff 结果分析

    git diff 的5个使用场景: 1.staging area和working area的文件 (无其他参数时) git diff   2.master分支和working area的文件 (用ma ...

  4. 20144306《网络对抗》MAL_恶意代码分析

    一.基础问题 1.如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪些,用什么方法来监控? 使用Windows自带的schtasks指 ...

  5. MongoDB $关键字 关系比较符号 $lt $lte $gt $gte $ne

    关系比较符: 小于:$lt 小于或等于:$lte 大于:$gt 大于或等于:$gte 不等于:$ne 属于:$in 查询中常见的 等于 大于 小于 大于等于 小于等于 等于 : 在MongoDB中什么 ...

  6. 15.IEnumerable和IEnumerator

    先说IEnumerable,我们每天用的foreach你真的懂它吗? 阅读目录 自己实现迭代器 yield的使用 怎样高性能的随机取IEnumerable中的值 我们先思考几个问题: 为什么在fore ...

  7. phpcms内容页替换

    一.浏览次数替换 <script type="text/javascript" src="{JS_PATH}js/jquery-1.11.2.min.js" ...

  8. os.path.join

    os.path.join()函数: 第一个以”/”开头的参数开始拼接,之前的参数全部丢弃. 以上一种情况为先.在上一种情况确保情况下,若出现”./”开头的参数,会从”./”开头的参数的上一个参数开始拼 ...

  9. Python多线程threading的使用

    一. threading的参数传递,参数之后的’,‘不能少,此处的’,‘是用来区分此参数作为元组(包含多个参数)来传递的,而不是单个参数传递 #coding:utf- import threading ...

  10. 看懂MSSQL执行计划,分析SQL语句执行情况

    打开SQL执行计划窗口 执行计划的图表是从右向左看的 SQL Server有几种方式查找数据记录 [Table Scan] 表扫描(最慢),对表记录逐行进行检查 [Clustered Index Sc ...