第八届河南省赛G.Interference Signal(dp)
G.Interference Signal
Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 17 [Submit][Status][Web Board]
Description
Dr.Kong’s laboratory monitor some interference signals. The interference signals can be digitized into a series of positive integer. May be, there are N integers a1,a2,…,an.
Dr.Kong wants to know the average strength of a contiguous interference signal block. the block must contain at least M integers.
Please help Dr.Kong to calculate the maximum average strength, given the constraint.
Input
The input contains K test cases. Each test case specifies:
* Line 1: Two space-separated integers, N and M.
* Lines2~line N+1: ai (i=1,2,…,N)
1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
Output
The input contains K test cases. Each test case specifies:
* Line 1: Two space-separated integers, N and M.
* Lines2~line N+1: ai (i=1,2,…,N)
1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
Sample Input
2
10 6
6
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5
9
Sample Output
6500
7333
HINT
Source
题解:让找长度大于等于M的连续子序列的最大平均值;
思路:简单dp,dp[i][j]=dp[i-1][j-1]+m[j];代表在j处前i个数的序列和;
然后判断找平均值;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
const int MAXN=2020;
int m[MAXN];
int dp[MAXN][MAXN];
double pp[MAXN][MAXN];
int main(){
int T,N,M;
SI(T);
while(T--){
SI(N);SI(M);
for(int i=1;i<=N;i++)SI(m[i]);
mem(dp,0);
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
dp[i][j]=dp[i-1][j-1]+m[j];
}
}
double x=0;
for(int i=M;i<=N;i++)
for(int j=M;j<=N;j++)
x=max(x,1.0*dp[i][j]/i);
printf("%d\n",(int)(1000*x));
}
return 0;
}
第八届河南省赛G.Interference Signal(dp)的更多相关文章
- 第八届河南省赛F.Distribution(水题)
10411: F.Distribution Time Limit: 1 Sec Memory Limit: 128 MB Submit: 11 Solved: 8 [Submit][Status] ...
- 第八届河南省赛D.引水工程(kruthcra+prime)
D.引水工程 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 118 Solved: 41 [Submit][Status][Web Board] D ...
- 第八届河南省赛C.最少换乘(最短路建图)
C.最少换乘 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 94 Solved: 25 [Submit][Status][Web Board] De ...
- 第八届河南省赛B.最大岛屿(dfs)
B.最大岛屿 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 30 Solved: 18 [Submit][Status][Web Board] De ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- POJ-2421Constructing Roads,又是最小生成树,和第八届河南省赛的引水工程惊人的相似,并查集与最小生成树的灵活与能用,水过~~~
Constructing Roads Time Limit: 2000MS Memory Limit: 65536K Description There are N v ...
- 第六届河南省赛 River Crossing 简单DP
1488: River Crossing Time Limit: 1 Sec Memory Limit: 128 MB Submit: 83 Solved: 42 SubmitStatusWeb ...
- Little Sub and Piggybank (杭师大第十二届校赛G题) DP
题目传送门 题意:每天能往存钱罐加任意实数的钱,每天不能多于起那一天放的钱数.如果某一天的钱数恰好等于那天的特价商品,则可以买,求最后的最大快乐值. 思路:先来一段来自出题人的题解: 显然的贪心:如果 ...
- G.Interference Signal---河南省第八届程序设计大赛(dp)
G.Interference Signal 时间限制: 2 Sec 内存限制: 128 MB提交: 47 解决: 18[提交][状态] 题目描述 Dr.Kong’s laboratory moni ...
随机推荐
- 移动端使用rem方法
(function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? ...
- linux 程序运行监控
一 . 使用supervise 是daemon-tools 的一个功能,系统的守护进程.在进程挂掉的时候可以自动重启. 二 安装 wget http://cr.yp.to/daemontools/ ...
- java面向对象之 多态 Polymorphism
多态(Polymorphism):用我们通俗易懂的话来说就是子类就是父类(猫是动物,学生也是人),因此多态的意思就是:父类型的引用可以指向子类的对象. 1.多态的含义:一种类型,呈现出多种状态 主要讨 ...
- discuz函数quote
public static function quote($str, $noarray = false) { if (is_string($str)) return '\'' . addcslashe ...
- 2016 Multi-University Training Contest 7 总结
第七场多校的排名稍微有了一点回升,然而也并不太乐观. 开场欣君秒出了02题的公式,磊哥开始打表验证,发现可行,一A. 我觉得06题有些思路,开始写,但是发现复杂度优化不下去,于是弃疗. 磊哥做了10题 ...
- [Leetcode][Python]24: Swap Nodes in Pairs
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 24: Swap Nodes in Pairshttps://oj.leetc ...
- Cpp again
1,
- linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客
linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客 linux中读写锁的rwlock介绍 2013-02-26 13:59:35 分类: C/C++ http://yaro ...
- Lua学习2 Lua小框架的搭建
看了上一篇Lua环境搭建具体http://blog.csdn.net/liuwumiyuhuiping/article/details/9196435 为了方便学习. 具体新开始搭建一下学习的小框架. ...
- (转)探讨:ASP.NET技术的学习顺序问题
探讨:ASP.NET技术的学习顺序问题 摘要:很多人对于ASP.NET的入门和学习顺序比较迷茫,今天让我们一起来跟随作者的思路学习探讨ASP.NET的学习顺序问题,希望有所帮助. 如果你已经有较多的面 ...