第八届河南省赛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 ...
随机推荐
- CentOS 6下配置本地用户访问vsftpd并赋予写权限
一.安装并测试可用性 1.安装命令 yum install vsftpd 2.配置防火墙,加入一行 -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT 在其它机测试 ...
- MySQL远程(IP)连接报错:Host 'IP地址' is not allowed to connect to this MySQL server
ERROR 1130: Host ’192.168.1.3′ is not allowed to connect to this MySQL server这是告诉你没有权限连接指定IP的主机,下面我们 ...
- Trafic
Dialogue 1 You took the wrong bus 你做错车了 A:Hi, I want to see the Terra Cotta Warriors in Xi'an. Coul ...
- MYSQL 错误日志
背景知识 : 就算我们不配置mysql的错误文件,它也会有一个默认的,在data文件夹下保存(.err文件) 还好这个文件保存在哪我们还是可以配置的 配置方法: log-err=E:\DB\mysql ...
- J2SE知识点摘记(十二)
1. File类 下面的构造方法可以用来生成File对象 File(String directoryPath) geName()用于返回文件名,getParent()返回父目录名,exist ...
- 使用MIDAS访问远程Access数据库
使用MIDAS访问远程Access数据库 Allen Tao(http://blog.csdn.net/allentao/) 2005-5-3 本文源码下载 访问远程数据库常用的办法是 ...
- MyBatis 最常见错误,启动时控制台无限输出日志
你是否遇到过下面的情况,控制台无限的输出下面的日志: Logging initialized using ‘class org.apache.ibatis.logging.log4j.Log4jImp ...
- DKNY_百度百科
DKNY_百度百科 DKNY
- collection系列用法-namedtuple()
namedtuple() 参考文章地址:http://www.cnblogs.com/herbert/p/3468294.html namedtuple是继承自tuple的子类.namedtuple和 ...
- 【Cocos2d TestCpp实例模仿一】-- ActionsTest
转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25252539 CCActionInterval(持续性动作) 位置性变化动作以To结束 ...