zoukankan      html  css  js  c++  java
  • 【动态规划】Überwatch

    Ü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.

    然后直接转移即可。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int N = 3e5+10;
     4 int dp[N],a[N],n,m;
     5 int main()
     6 {
     7     scanf("%d%d",&n,&m);
     8     //m++;
     9     for(int i=1;i<=n;i++)
    10         scanf("%d",&a[i]);
    11     int res = 0 ;
    12     for(int i=1;i<=n;i++){
    13         dp[i] = dp[i-1] ;
    14         if( i>=(m+1) ){
    15             dp[i] = max( dp[i-m] + a[i] , dp[i] );
    16             res = max( res , dp[i]) ;
    17         }
    18     }
    19     printf("%d
    ",res );
    20     return 0;
    21 }
    View Code
  • 相关阅读:
    PL/SQL跨库查询数据
    oracle 两个时间相减
    导出Excel格式数据
    Java导出pdf文件数据
    $.ajax相关用法
    oracle 删除掉重复数据只保留一条
    常用Oracle操作语句
    JS请求服务器,并返回信息,请求过程中不需要跳转页面
    tomcat部署web项目的3中方法
    Date()日期转换和简单计算
  • 原文地址:https://www.cnblogs.com/Osea/p/11397589.html
Copyright © 2011-2022 走看看