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
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.
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.
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); } ; }