zoukankan      html  css  js  c++  java
  • bzoj2748 水dp

    2748: [HAOI2012]音量调节

    Time Limit: 3 Sec  Memory Limit: 128 MB
    Submit: 827  Solved: 548
    [Submit][Status][Discuss]

    Description

    一个吉他手准备参加一场演出。他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量。在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改变的音量是多少。每一次改变音量,他可以选择调高也可以调低。
    音量用一个整数描述。输入文件中给定整数beginLevel,代表吉他刚开始的音量,以及整数maxLevel,代表吉他的最大音量。音量不能小于0也不能大于maxLevel。输入文件中还给定了n个整数c1,c2,c3…..cn,表示在第i首歌开始之前吉他手想要改变的音量是多少。
    吉他手想以最大的音量演奏最后一首歌,你的任务是找到这个最大音量是多少。

    Input

    第一行依次为三个整数:n, beginLevel, maxlevel。
    第二行依次为n个整数:c1,c2,c3…..cn。

    Output

    输出演奏最后一首歌的最大音量。如果吉他手无法避免音量低于0或者高于maxLevel,输出-1。

    Sample Input

    3 5 10
    5 3 7

    Sample Output

    10

    HINT

    1<=N<=50,1<=Ci<=Maxlevel 1<=maxlevel<=1000

    0<=beginlevel<=maxlevel

    Source

    program hehe;
    var
    n,i,j,q,max:longint;
    d:array[0..50,0..1000] of boolean;
    c:array[0..50] of longint;
    begin
    readln(n,q,max);
    fillchar(d,sizeof(d),false);
    for i:=1 to n do read(c[i]);
    d[0,q]:=true;
    for i:=1 to n do
    for j:=0 to max do
    begin
    if j-c[i]>=0 then
    if d[i-1,j-c[i]] then d[i,j]:=true;
    if j+c[i]<=max then
    if d[i-1,j+c[i]] then d[i,j]:=true;
    end;
    q:=-1;
    for i:=max downto 1 do
    if d[n,i] then
    begin
    q:=i;
    break;
    end;
    if q<>-1 then writeln(q)
    else writeln(-1);
    end.

  • 相关阅读:
    codeforces 455C 并查集
    poj 3501 Escape from Enemy Territory 预处理+二分+bfs
    POJ 2110 Mountain Walking 二分+bfs
    poj1637 Sightseeing tour 混合图欧拉回路判定
    ubuntu禁用super(win)键
    win10 ubuntu双系统安装后无法引导进入ubuntu
    python2限制函数传入的关键字参数
    python限制函数执行时间
    python classmethod 和 staticmethod的区别
    centos sendmail 启动慢
  • 原文地址:https://www.cnblogs.com/chensiang/p/4581596.html
Copyright © 2011-2022 走看看