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. hbase+hive应用场景

    一.Hive应用场景本文主要讲述使用 Hive 的实践,业务不是关键,简要介绍业务场景,本次的任务是对搜索日志数据进行统计分析.集团搜索刚上线不久,日志量并不大 .这些日志分布在 5 台前端机,按小时 ...

  2. 详解MySQL三项实用开发知识

    其实项目应用的瓶颈还是在db端,在只有少量数据及极少并发的情况下,并不需要多少的技巧就可以得到我们想要的结果,但是当数据量达到一定量级的时 候,程序的每一个细节,数据库的设计都会影响到系统的性能.这里 ...

  3. [python]使用pexpect模块进行批量scp

    #!/usr/bin/env python# -*- coding: utf-8 -*- #wangxiaofei #awcloud自动化测试 import time,osimport threadi ...

  4. javascript面向对象实例

    非私有属性 function Student(name, gender, age, grade, teacher){ this.name = name; this.gender = gender; t ...

  5. 书签(Bookmarks)

    工作台允许使用者在文件中创建书签,通过这些书签,使用者可以从书签视图里快速打开这些文件,并跳转到相应的行. (1)在编辑器左边灰色的区域里单击鼠标右键,在弹出的菜单里选择“Add Bookmark.. ...

  6. 无聊之作,RPGdemo制作(一)角色state模式

    今天周末,在家无事可做,不知道为什么,突发奇想,想写一个RPG游戏的demo玩玩.所以就记录一下. 第一步要做的是,为以后的角色类写一个state模式的类,考虑到可能以后会用到,所以用模版来实现, / ...

  7. NET知识大纲

    第一部分 C#编程基础 1.(30)变量.运算符(+.-.*./.++.--.括号.==.!=.>.<.>=.<=.&&.||).流程控制(if.while.f ...

  8. Leetcode: Length of Last Word in python

    Length of Last Word Total Accepted: 47690 Total Submissions: 168587     Given a string s consists of ...

  9. [转]Javascript定义类的三种方法

    作者: 阮一峰 原文地址:http://www.ruanyifeng.com/blog/2012/07/three_ways_to_define_a_javascript_class.html 将近2 ...

  10. Spark及其应用场景初探

    最近老大让用Spark做一个ETL项目,搭建了一套只有三个结点Standalone模式的Spark集群做测试,基础数据量大概8000W左右.看了官方文档,Spark确实在Map-Reduce上提升了很 ...