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. Android studio gradle 打包 那些事

    总结了一下 目前觉得比较好用的gradle 和一些打包 经验.放在这里. 首先说下 渠道号 这个概念,我们经常会统计我们的api 访问来源 是来自于那个app store,这有利于 我们针对性的推广. ...

  2. JS面向对象的学习

    1.面向对象 var arr = new Array(); //[] //我们把系统自带的对象,叫做系统对象 var arr = []; arr.number = ; //对象下面的变量:叫做对象的属 ...

  3. C#循环声明一个类

    宗旨就是把实例化的类循环放到字典里面 Dictionary<string, Data> dic = new Dictionary<string, Data>(); ; i &l ...

  4. 基于jQuery的AJAX和JSON的实例

    通过jQuery内置的AJAX功能,直接访问后台获得JSON格式的数据,然后通过jQuer把数据绑定到事先设计好的html模板上,直接在页面上显示. 我们先来看一下html模板:            ...

  5. Creole

    Home           Bisher besucht:    AnzeigenAnhängeInfo           The Creole 1.0 project has been succ ...

  6. PHP Header 缓存 --- Header 参数说明

    1. Accept:告诉WEB服务器自己接受什么介质类型,*/* 表示任何类型,type/* 表示该类型下的所有子类型,type/sub-type. 2. Accept-Charset:   浏览器申 ...

  7. vs2010 please select a valid location in the repository

    vs2010 please select a valid location in the repository AnkhSvn版本有问题,我后来使用2.1就ok了记录一下

  8. 如何查看python selenium的api

    1. 打开命令行: command+R2. 输入: python -m pydoc -p 4567,然后:Enter3. 然后在浏览器中访问http://localhost:45674. 按ctrl+ ...

  9. slowhttps安装及使用心得

    运行及安装环境,kali. 到googlecode上下载安装包,cd到安装目录./configure 运行完毕后输入make 结束后make install 简单点就直接apt-get install ...

  10. Thread .join 的用法一例

    在使用身份证读卡器时,要求 1. 身份证读到身份证 就 停止线程. 2. 关闭界面时会 自动停止调用读身份证的线程.这时候就需要用到 Thead.join 例子如下: Thread thread; p ...