世上只有一种英雄主义,就是在认清生活真相之后依然热爱生活。

大家有空去我的网站逛逛呀!   http://www.mxnzqh.cn/

A - Max Sum Plus Plus

Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

Given a consecutive number sequence S 1, S 2, S3, S 4 ... S x, ... S n (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ S x ≤ 32767). We define a function sum(i, j) = S i + ... + S j (1 ≤ i ≤ j ≤ n).

Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i 1, j 1) + sum(i 2, j 2) + sum(i 3, j 3) + ... + sum(i m, jm) maximal (i x ≤ i y ≤ j x or i x ≤ j y ≤ j xis not allowed).

But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(i x, j x)(1 ≤ x ≤ m) instead. ^_^

Input

Each test case will begin with two integers m and n, followed by n integers S 1, S 2, S 3 ... S n
Process to the end of file.

Output

Output the maximal summation described above in one line.

Sample Input

1 3 1 2 3
2 6 -1 4 -2 3 -2 3

Sample Output

6
8

Hint

Huge input, scanf and dynamic programming is recommended.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
//dp[i][j]表示前j个数选择i段的最大值
int m,n,s[1000010],dp[1000010],q[1000010],mx;
int main()
{while(cin>>m>>n){for(int i=1; i<=n; i++)cin>>s[i];memset(dp,0,sizeof(dp));memset(q,0,sizeof(q));for(int i=1; i<=m; i++){mx=-inf;for(int j=i; j<=n; j++){dp[j]=max(dp[j-1],q[j-1])+s[j];q[j-1]=mx;mx=max(dp[j],mx);}}cout<<mx<<endl;}return 0;
}

B - Ignatius and the Princess IV

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

"But what is the characteristic of the special integer?" Ignatius asks.

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

Output

For each test case, you have to output only one line which contains the special number you have found.

Sample Input

5
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1

Sample Output

3
5
1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N,s[1000010],x,jg;
int main()
{while(cin>>N){memset(s,0,sizeof(s));for(int i=0; i<N; i++){cin>>x;s[x]++;if(s[x]==N/2)jg=x;}cout<<jg<<endl;}return 0;
}

C - Monkey and Banana

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.

They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.

Input

The input file will contain one or more test cases. The first line of each test case contains an integer n, 
representing the number of different blocks in the following data set. The maximum value for n is 30. 
Each of the next n lines contains three integers representing the values xi, yi and zi. 
Input is terminated by a value of zero (0) for n.

Output

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,dp[210],tt=1,ct;
struct node
{int x;int y;int z;
} p[210];
bool cmp(node a,node b)
{if(a.x==b.x)return a.y>b.y;return a.x>b.x;
}
void plzh(int xx,int yy,int zz)
{p[ct].x=xx;p[ct].y=yy;p[ct].z=zz;ct++;
}
int main()
{while(scanf("%d",&n)&&n!=0){int xx,yy,zz,jg=0;ct=0;memset(dp,0,sizeof(dp));for(int i=0; i<n; i++){scanf("%d%d%d",&xx,&yy,&zz);plzh(xx,yy,zz);plzh(xx,zz,yy);plzh(yy,xx,zz);plzh(yy,zz,xx);plzh(zz,xx,yy);plzh(zz,yy,xx);}sort(p,p+ct,cmp);for(int i=0; i<ct; i++){dp[i]=p[i].z;for(int j=0; j<i; j++){if(p[i].x<p[j].x&&p[i].y<p[j].y)dp[i]=max(dp[i],dp[j]+p[i].z);jg=max(jg,dp[i]);}}printf("Case %d: maximum height = %d\n",tt++,jg);}return 0;
}

D - Doing Homework

Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test, 1 day for 1 point. And as you know, doing homework always takes a long time. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. 
Each test case start with a positive integer N(1<=N<=15) which indicate the number of homework. Then N lines follow. Each line contains a string S(the subject's name, each string will at most has 100 characters) and two integers D(the deadline of the subject), C(how many days will it take Ignatius to finish this subject's homework).

Note: All the subject names are given in the alphabet increasing order. So you may process the problem much easier.

Output

For each test case, you should output the smallest total reduced score, then give out the order of the subjects, one subject in a line. If there are more than one orders, you should output the alphabet smallest one.

Sample Input

2
3
Computer 3 3
English 20 1
Math 3 2
3
Computer 3 3
English 6 3
Math 6 3

Sample Output

2
Computer
Math
English
3
Computer
English
Math

Hint

In the second test case, both Computer->English->Math and Computer->Math->English leads to reduce 3 points, but the
word "English" appears earlier than the word "Math", so we choose the first order. That is so-called alphabet order.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int T,N,yx[40010],sj[40010],dp[40010];
struct node
{char s[110];int D;int C;
} p[40010];
void shuchu(int m)
{if(!m)return;shuchu(m-(1<<yx[m]));cout<<p[yx[m]].s<<endl;
}
int main()
{cin>>T;while(T--){cin>>N;getchar();for(int i=0; i<N; i++)cin>>p[i].s>>p[i].D>>p[i].C;int m=1<<N;for(int i=1; i<m; i++){dp[i]=inf;for(int j=N-1; j>=0; j--){int ls=1<<j;if(!(i&ls))continue;int fs=sj[i-ls]+p[j].C-p[j].D;if(fs<0)fs=0;if(dp[i]>dp[i-ls]+fs){dp[i]=dp[i-ls]+fs;sj[i]=sj[i-ls]+p[j].C;yx[i]=j;}}}cout<<dp[m-1]<<endl;shuchu(m-1);}return 0;
}

E - Super Jumping! Jumping! Jumping!

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. 
Your task is to output the maximum value according to the given chessmen list.

Input

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

Sample Output

4
10
3
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,dp[1010], a[1010];
int main()
{while(cin>>n&&n!=0){int jg = 0;for(int i=0; i<n; i++){cin>>a[i];dp[i] = a[i];for(int j=0; j<i; j++)if(a[j] < a[i])dp[i] = max(dp[i], dp[j]+a[i]);jg = max(jg, dp[i]);}cout<<jg<<endl;}return 0;
}

F - Piggy-Bank

Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid.

But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it's weight in grams.

Output

Print exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the piggy-bank is X." where X is the minimum amount of money that can be achieved using coins with the given total weight. If the weight cannot be reached exactly, print a line "This is impossible.".

Sample Input

3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4

Sample Output

The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
//完全背包
int n,t,e,f,w[50010],p[50010],dp[50010];
int main()
{cin>>t;while(t--){cin>>e>>f;f-=e;//硬币重量cin>>n;for(int i=0; i<n; i++)cin>>p[i]>>w[i];for(int i=0; i<=f; i++)dp[i]=inf;dp[0]=0;for(int i=0; i<n; i++)for(int j=w[i]; j<=f; j++)dp[j]=min(dp[j],dp[j-w[i]]+p[i]);if(dp[f]==inf)printf("This is impossible.\n");elseprintf("The minimum amount of money in the piggy-bank is %d.\n",dp[f]);}return 0;
}

YTU2018级每周训练-动态规划1相关推荐

  1. BUCTOJ - 2023上半年ACM蓝桥杯每周训练题-1-A~K题C++Python双语版

    文章目录 BUCTOJ - 2023上半年ACM&蓝桥杯每周训练题-1-A~K题C++Python双语版 前言 问题 A: 1.2 神奇兔子数列 题目描述 输入 输出 解题思路 AC代码 C+ ...

  2. 深入探究递归神经网络:大牛级的训练和优化如何修成?

     深入探究递归神经网络:大牛级的训练和优化如何修成? 摘要:不同于传统FNN,RNN无需在层面之间构建,同时引入定向循环,能够更好地处理高维度信息的整体逻辑顺序.本文中,MIT的Nikhil Bu ...

  3. 19级算法训练赛第七场

    19级算法训练赛第七场 传送门:https://vjudge.net/contest/362412#problem/J A - 程序设计:合并数字 蒜头君得到了 n 个数,他想对这些数进行下面这样的操 ...

  4. 每周训练5小时,自信从容进大厂 | 20年码龄的技术VC大咖为你的面试指点迷津

    3月4日(周四).7日(周日)的两场直播都已经结束,共有上百位同学在线观看,感谢猿粉们的积极参与! 技术大咖"白月光"老师通过讲解三位学生的技术成长经历,给大厂面试划重点,我们一起 ...

  5. GDUT22级寒假训练专题四

    题解 C - Beautiful Numbers 传送门 题意   Vitaly有一些奇怪的癖好,比如他特别爱两个小于10的数字a和b.Vitaly定义十进制表示下每一位都是a或b的数为"好 ...

  6. 2019级寒假训练-Java

    文章目录 选择题 单选题 编程题 7-1 整型数除法异常处理 (10 分) 7-2 使用HashMap实现查找功能 (10 分) 7-3 统计字母和空格出现的次数 (10 分) 7-4 自定义异常Ci ...

  7. 算法训练——动态规划

    今天要跟大家分享的是关于动态规划的一些例题,因为动态规划是算法中非常重要的一部分,掌握其思想是必要的,只有多刷题才能更好地理解并掌握它 题目:

  8. HPU 18级个人训练 11月15日

    传送门 D题 题意:波浪数组满足四个条件:1.至少两个元素.2.奇数位的数都相等.3.偶数位的数都相等.4.奇数位和偶数位的数不相等.给你一个数组(数组中元素不大于c),你要从中找出波浪数组的最大长度 ...

  9. GZHU18级寒假训练:Aquarius's Trial F

    可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下 ...

最新文章

  1. 定义AI,麦卡锡、图灵、乔丹...我们听谁的?
  2. 友元类实例:日期类 学生类
  3. 阻抗匹配工具_工具 | 9R Fret Polishing Wheels 品丝抛光轮
  4. mysql表中插中文报错_向mysql表中插入含有中文的数据时报错:[Err] 1366
  5. @Conditional进行条件判断等
  6. C++编程练习:多态实验——设计一个基类Shapes,Shapes类公有派生产生矩形类Rectangle和圆类Circle
  7. 如何通过 反射 调用某个对象的私有方法?
  8. JEECG 3.2版本发布,基于代码生成器的智能开发平台
  9. 免除抠图困扰,专供PNG图片素材网站你知道么?
  10. 用c语言写的电话簿的程序,用C语言散列表实现电话薄
  11. 【干货】阿里直播平台的架构演进
  12. IIS 配置 url 重写...
  13. 计算单应性矩阵 python_计算视觉——相机参数标定法
  14. python tkinter教程-事件绑定_详解python tkinter教程-事件绑定
  15. 数学建模【SPSS 下载-安装、方差分析与回归分析的SPSS实现(软件概述、方差分析、回归分析)】
  16. 一个粗糙的js分页判断
  17. PHP在线手册 中文版
  18. 云计算:几种aaS(as a Server)
  19. Android 接口的default 方法运行时报错AbstractMethodError
  20. 360 os3.0 android7.1,360OS 3.0系统

热门文章

  1. STF开源框架之minicap工具
  2. Selenium基本二次封装
  3. webstorm背景颜色修改为护眼豆沙绿
  4. 家庭财务管理系统(C++面向对象课程设计附课设报告)
  5. 百度地图api周边搜索功能
  6. 4417. 神奇的字符串
  7. PMP备考错题集-模拟三
  8. 计算机键盘录入指法视频,第一章计算机文录入键盘指法.ppt
  9. SAP FI系统配置-资产相关
  10. 网管软件哪家比较好用