1022: Hard problem

Time Limit: 1 Sec   Memory Limit: 128 MB

Submit: 43  
Solved: 12

Description

The cat gets N mice from dreamone, and she can choose K mice from them as the order which is listed from 
left to right for dinner. But there is a limitation that the second mouse is no bigger than the first one, the third 
one is no bigger than the second one….the Kth one is no bigger than the (K-1) th one. Actually, there is always 
not a single method to choose the K mice from the N mice as the way described above; we can assume there 
is M ways. This time, the cat of dreamone’s has thought another hard problem:  
For each way, there is always a value for the Kth mouse. She wants to know the biggest value for the Kth 
mouse of all the M ways. Can you get it? Of course, not all of you have understood the idea, so there is an 
example blew: 
We can assume N=4, K=2. 
The N (N=4) numbers represented the N mice are given blew from left to right: 
4 6 5 4 
According to the rules above, we can get four ways for choosing K mice, such as: 
4 4;  6 5;  6 4;  5 4 
So the answer is 5.because the value 5 is the biggest one of the four ways for the Kth number.  
If the cat can not solve the problem as quickly as she can, she will feel very boring, so she turns to you, a 
topcoder of SWUST, for help. Can you help her? 

Input

The first line of input will be a positive integer indicating how many test cases will be included (T). Each of 
the next T cases will contain two parts: 
The first part: two integer N, K (1<=N<=10000, 1<=K<=10) 
The second part: N numbers (which is no larger than 1000000) represented the N mice from left to right. 

Output

For each test, you should output the biggest value for the Kth numbers of all the manners. If you can not find 
any way to choose the Kth mouse, just output “OH, NO” instead. 

Sample Input

4 2 
4 6 5 4 
4 2 
1 2 3 4

Sample Output

OH,NO
思路:dp问题,找好状态转移方程。
代码:
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
#define MAX 10000
int line[MAX+10];
int num[11];
int dp[MAX+10][11];
int get_min(int a,int b)
{
return a>b?b:a;
}
int get_max(int a,int b)
{
return a>b?a:b;
}
int main()
{
//freopen("E.in","r",stdin);
//freopen("E1.out","w",stdout);
int n,m,t,i,j,flag,ans;
scanf("%d",&n);
while(n--)
{
flag=0;ans=0;
scanf("%d%d",&m,&t);
for(i=0;i<m;i++)
scanf("%d",&line[i]);
if(t>m)
printf("OH,NO\n");
else
{
memset(num,-1,sizeof(num));
memset(dp,-1,sizeof(dp));
num[0]=line[0];
for(i=0;i<m;i++)
{
dp[i][0]=line[i];
int temp=get_min(i,t);
for(j=temp;j>=1;j--)
{
if(num[j-1]==-1)
continue;
else if(num[j-1]>=line[i])
{
dp[i][j]=line[i];
num[j]=get_max(num[j],line[i]);
}
}
num[0]=get_max(num[0],line[i]);
}
for(i=t-1;i<m;i++)
{
if(dp[i][t-1]>ans)
{
ans=dp[i][t-1];
flag=1;
}
}
if(flag)
printf("%d\n",ans);
else
printf("OH,NO\n");
}
}
return 0;
}

FROM:暑假第三场


Hard problem的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. SPF详解2

    什么是SPF?   这里的SPF不是防晒指数,而是指Sender Policy Framework.翻译过来就是发信者策略架构,比较拗口,通常都直接称为SPF.   SPF是跟DNS相关的一项技术,它 ...

  2. 企业网站DDOS防护解决方案

    随着网络的普及,越来越多的企业开始了上网之路,由于网络安全知识的欠缺,很多企业以为做一个网站就 等于 网络化了,于是狠花血本请专业网络公司制作出各种漂亮的网页.但做完才发现,网络上的各种漏洞的DDOS ...

  3. dword word byte 相互转换 .xml

    pre{ line-height:1; color:#800080; background-color:#d2c39b; font-size:16px;}.sysFunc{color:#627cf6; ...

  4. openGl从零开始之添加颜色

    OpenGL 支持两种颜色模式:一种是 RGBA模式,一种是 颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据,即通过每一个像素的颜色,来改变整体图形的颜色.不同的是, RGBA ...

  5. bzoj1391 最大权闭合子图(also最小割、网络流)

    一道裸的最小割的题,写一下只是练练手. 表示被卡M,RE不开心.一道裸题至于吗? 再次复习一下最大权闭合子图: 1.每一个点若为正权,与源点连一条容量为绝对值权值的边.否则连向汇点一条容量为绝对值权值 ...

  6. python3 多线程的基本用法

    #coding=utf-8 import threading #导入threading包 from time import sleep import time   def task1():     p ...

  7. pycharm出现乱码

    1. 'gbk' codec can't encode character u'\xb8' 解决办法 import sys reload(sys)sys.setdefaultencoding('utf ...

  8. 黑马程序员——有关protocol代理模式的举例说明

    学习了protocol协议的基本原理和使用方法之后 ,下面就看一下在程序中是怎么体现这种代理思想的. 假定有个人jack需要找一个厨师为自己做饭,当他想要吃饭的时候就可以让厨师给他做好饭.这一需求如何 ...

  9. junit4新框架hamcrest

    Hamcrest是一个书写匹配器对象时允许直接定义匹配规则的框架.有大量的匹配器是侵入式的,例如UI验证或者数据过滤,但是匹配对象在书写灵活的测试是最常用.本教程将告诉你如何使用Hamcrest进行单 ...

  10. 安装 nodejs图像处理模块 sharp

    sudo npm install sharp 报错: ERROR: Please install libvips by running: brew install homebrew/science/v ...