zoukankan      html  css  js  c++  java
  • BZOJ2748: [HAOI2012]音量调节

    【传送门:BZOJ2748


    简要题意:

      给出初始音量和能承受的最大音量,共有n首歌,每首歌可以增加或减少c[i]的音量,求出n首歌后的最大音量


    题解:

      DP水题

      设f[i][j]为第i首歌时能否达到j的音量,然后。。这么水就不用解释了吧


    参考代码:

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    bool f[51][1100];
    int c[51];
    int main()
    {
        int n,bl,ml;
        scanf("%d%d%d",&n,&bl,&ml);
        memset(f,false,sizeof(f));
        f[0][bl]=true;
        for(int i=1;i<=n;i++) scanf("%d",&c[i]);
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=ml;j++)
            {
                if(j+c[i]<=ml&&f[i-1][j]==true) f[i][j+c[i]]=true;
                if(j-c[i]>=0&&f[i-1][j]==true) f[i][j-c[i]]=true;
            }
        }
        for(int i=ml;i>=0;i--)
        {
            if(f[n][i]==true)
            {
                printf("%d
    ",i);
                return 0;
            }
        }
        printf("-1
    ");
        return 0;
    }

     

  • 相关阅读:
    图形验证码---pillow
    vue富文本编辑器vue-quill-editor
    django邮件发送
    Django REST Framework JWT
    jwt验证
    使用django的用户表进行登录管理
    [转]CSRF漏洞详细说明
    Django框架10
    Django框架09
    Django框架08
  • 原文地址:https://www.cnblogs.com/Never-mind/p/8506173.html
Copyright © 2011-2022 走看看