7
27
2015
8

BZOJ 2748: [HAOI2012]音量调节

Description

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

动态规划 定义bool型 f【第i首歌】【音量】 如果当前可以达到就用它更新下一首歌的状态。

/**************************************************************
    Problem: 2748
    User: 1115825064
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1328 kb
****************************************************************/
 
#include<iostream>
#include<cstring>
#include<cstdio>
 
using namespace std;
 
int ma,n;
bool f[55][1010];
 
int main()
{
//  freopen("1.txt","r",stdin);
    int aa;
    scanf("%d%d%d",&n,&aa,&ma);
    f[0][aa]=1;
    for(int i=0;i<n;++i)
    {
        int c;
        scanf("%d",&c);
        for(int j=0;j<=ma;++j)
        { 
            if(f[i][j])
            {
                if(j+c<=ma) f[i+1][j+c]=1;
                if(j-c>=0) f[i+1][j-c]=1;
            }
        }
    }
    int a=-1;
    for(int j=0;j<=ma;++j)
    {
        if(f[n][j])
            a=j;
    }
    printf("%d",a);
    return 0;
         
}

Category: 未分类 | Tags: | Read Count: 454
Avatar_small
Matthew Wade 说:
2025年3月07日 15:01

I love reading through a post that may make people feel. Additionally, thank you for enabling me personally to comment! Binary Signals

Avatar_small
Matthew Wade 说:
2025年3月11日 15:35

This is the sort of information I’ve long been in search of. Thanks for posting this information. http://www.5starsstocks.com/

Avatar_small
Matthew Wade 说:
2025年3月16日 00:07

Your blog is one of the better blogs I’ve came across in months. Thank you for your posts and all the best with your work and blog. Looking forward to reading new entries! Binary Options

Avatar_small
Matthew Wade 说:
2025年3月21日 23:22

Many thanks for placing up this post, I feel every person will thanks for that. number generator

Avatar_small
Matthew Wade 说:
2025年3月25日 17:57

Thanks for this post, I am a big big fan of this internet site would like to proceed updated. 바카라사이트

Avatar_small
Matthew Wade 说:
2025年3月28日 14:03

Hello! I would choose to supply a huge thumbs up with the great info you have here with this post. I will be returning to your website to get more soon. binary options signals

Avatar_small
Matthew Wade 说:
2025年3月31日 19:52

Woh I like your blog posts, bookmarked ! . crypto bot

Avatar_small
Matthew Wade 说:
2025年4月20日 23:44

Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! افلام مترجمة


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com