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. 【转】Github轻松上手3-使用Tower图形化界面工具创建和管理repo

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzib.html 除了在命令行中输入特定的命令,另外一种方式就是用第三方的可视化工具,比如Mac下的Tow ...

  2. 实现LoaderCallbacks接口动态循环加载网上图片并展示在手机屏幕上 ...

    1.布局xml文件 activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/re ...

  3. phonegap 使用极光推送实现消息推送

    最近一直在研究各种推送,ios的由于是apns,比较容易实现,但是andriod的就比较麻烦.后来看了很多解决方案,gcm明显是不行的,其他的方案更是一头雾水,而且需要做第二次开发,太麻烦,后来就选择 ...

  4. 使用java写入excel文件

    要操作excle文件,首先要下载jxl.jar文件,我用的版本是2.6.下载地址:http://www.andykhan.com/jexcelapi/download.html. Java Excel ...

  5. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list(self, locator, *items)

    def unselect_from_list(self, locator, *items): """Unselects given values from select ...

  6. CSS学习进度备忘

    书签:“CSS 高级”跳过:另外跳过的内容有待跟进 __________________ 学习资源:W3School. _________________ 跳过的内容:1.“CSS id 选择器”的“ ...

  7. 第一天开通博客,就粗略写一下刚了解TCP/IP协议工作过程

    Tcp/Ip协议分为四层:底层到高层顺序 链路层(硬件,网卡这些) 网络层(选择一条传输路径,如何从一台计算机请求另一条计算机) 传输层(遵循TCP(传输控制协议),UDP(用户数距协议)这些协议) ...

  8. MFC中GetPrivateProfileString相关函数

    项目中用到了这个函数,所以了解了一下,参考了一些博客: http://blog.sina.com.cn/s/blog_a599b5960101tsbk.html http://blog.csdn.ne ...

  9. mongodb使用中遇到的问题汇总

    1. 每次重新打开mongo,都会显示:forked process:xxxx ,然后用 find -name mongod.lock 进行搜索,发现在 ./var/lib/mongodb/ 目录下又 ...

  10. Windows Azure存储容器私有,公共容器,公共Blob的区别

    当我们在Windows Azure中创建或编辑存储的容器时,需要选择访问类型,本文将描述一下这三个选项的区别. 1. 私有: 默认选项,顾名思义,用户不能通过URL匿名进行访问容器或容器内的任何Blo ...