Überwatch

题目描述

The lectures are over, the assignments complete and even those pesky teaching assistants have nothing left to criticize about your coding project. Time to play some video games! As always, your procrastinating self has perfect timing: Cold Weather Entertainment just released Überwatch, a competitive first person video game!
Sadly, you aren’t very good at these kind of games. However, Überwatch offers more than just skill based gameplay. In Überwatch you can defeat all opponents in view with a single button press using your ultimate attack. The drawback of this attack is that it has to charge over time before it is ready to use. When it is fully charged you can use it at any time of your choosing.
After its use it immediately begins to charge again.
With this knowledge you quickly decide on a strategy:
• Hide from your opponents and wait for your ultimate attack to charge.
• Wait for the right moment.
• Defeat all opponents in view with your ultimate attack.
• Repeat.
After the game your teammates congratulate you on your substantial contribution. But you wonder: How many opponents could you have defeated with optimal timing?
The game is observed over n time slices. The ultimate attack is initially not charged and requires m time slices to charge. This first possible use of the ultimate attack is therefore in the (m+1)-th time slice. If the ultimate attack is used in the i-th time slice, it immediately begins charging again and is ready to be fired in the (i + m)-th time slice.

输入

The input consists of:
• one line with two integers n and m, where
– n (1 ≤ n ≤ 300 000) is the game duration;
– m (1 ≤ m ≤ 10) is the time needed to charge the ultimate attack in time slices.
• one line with n integers xi (0 ≤ xi ≤ 32) describing the number of opponents in view during a time slice in order.

输出

Output the maximum number of opponents you can defeat.

样例输入

4 2
1 1 1 1

样例输出

1

【题解】

题意说,有一个大招每次放完还需要等待m次,直接考虑dp[i],从开始到i这个时间内获取的最大值。

注意:第一个位置的时候为0,然后如果放完大招后下一次充能从1开始。【题目说得很清楚】

This first possible use of the ultimate attack is therefore in the (m+1)-th time slice.
If the ultimate attack is used in the i-th time slice, it immediately begins charging again and is ready to be fired in the (i + m)-th time slice.

然后直接转移即可。

 #include<bits/stdc++.h>
using namespace std;
const int N = 3e5+;
int dp[N],a[N],n,m;
int main()
{
scanf("%d%d",&n,&m);
//m++;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int res = ;
for(int i=;i<=n;i++){
dp[i] = dp[i-] ;
if( i>=(m+) ){
dp[i] = max( dp[i-m] + a[i] , dp[i] );
res = max( res , dp[i]) ;
}
}
printf("%d\n",res );
return ;
}

【动态规划】Überwatch的更多相关文章

  1. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  2. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

  3. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  4. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  5. C#动态规划查找两个字符串最大子串

     //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {            ...

  6. C#递归、动态规划计算斐波那契数列

    //递归         public static long recurFib(int num)         {             if (num < 2)              ...

  7. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  8. 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划

    [BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...

  9. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

随机推荐

  1. Python性能监控

    profiler是一个程序,用来描述运行时的程序性能,并且从不同方面提供统计数据加以表述.Python中含有3个模块提供这样的功能,分别是cProfile, profile和pstats.这些分析器提 ...

  2. 学JavaScript的感想小结1

    学了几天的Javascript,刚开始就在想Java和JavaScript有什么不同,算了其实两个咱都不会也没多想了,带着这个好奇心学菜鸟教程,没想到还真得到了解答,瞬间兴趣提升,愿意追根溯源的教程还 ...

  3. 分区工具parted的使用方法

    一.         parted的用途及说明 概括使用说明: parted用于对磁盘(或RAID磁盘)进行分区及管理,与fdisk分区工具相比,支持2TB以上的磁盘分区,并且允许调整分区的大小.   ...

  4. python 使微信自动回复

    https://zhuanlan.zhihu.com/p/308999073 今天是鄙人的生日,欢luo过后想写点关于itchat的文章~ (不小心暴露年龄了,是的,我已经16岁了~~) 言归正传,这 ...

  5. 创建Bitmap之Bitmap静态方法使用示例

    package com.loaderman.customviewdemo; import android.app.Activity; import android.content.Intent; im ...

  6. python方法未绑定错误

    相信 Python 程序员多多少少都和我一样遇到过 Method Unbound Error,直译过来就是 “方法未绑定错误”,虽然搜索之后知道了使用 @classmethod 这样的装饰起后就可以解 ...

  7. 【精华】PHP网站验证码不显示的终结解决方案

    PHP网站验证码不显示,这个是个很基础的PHP问题了,不过有点时候会比较让开发者比较头疼了.很多解决方案仅仅考虑到gd2,却忽略了另外一个很重要的因素了,相信在了解本教程之后,验证码不显示基本上就不算 ...

  8. 002-创建型-02-抽象工厂模式(Abstract Factory)

    一.概述 抽象工厂模式提供同一个创建一系列相关或相互依赖对象的接口,无须指定它们具体的类 抽象工厂模式是所有形态的工厂模式中最为抽象和最具一般性的一种形态.抽象工厂模式是指当有多个抽象角色时,使用的一 ...

  9. 009-Linux nohup

    一.基础概述 1./dev/null 可以将/dev/null看作"黑洞". 它非常等价于一个只写文件. 所有写入它的内容都会永远丢失. 而尝试从它那儿读取内容则什么也读不到. 然 ...

  10. 性能测试-Linux资源监控⽅式

    Linux资源监控⽅式 1. 命令 2. 第三⽅⼯具(nmon) 3. LR(需要安装RPC相应服务包和开启服务)(略)   ⼀.命令 ⽅式 1. top (系统资源管理器) 2. vmstat (查 ...