题目描述

一个吉他手准备参加一场演出。他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都需要改变一次音量。在演出开始之前,他已经做好一个列表,里面写着每首歌开始之前他想要改变的音量是多少。每一次改变音量,他可以选择调高也可以调低。

音量用一个整数描述。输入文件中整数beginLevel,代表吉他刚开始的音量,整数maxLevel,代表吉他的最大音量。音量不能小于0也不能大于maxLevel。输入中还给定了n个整数c1,c2,c3,...,cn,表示在第i首歌开始之前吉他手想要改变的音量是多少。

吉他手想以最大的音量演奏最后一首歌,你的任务是找到这个最大音量是多少。

输入输出格式

输入格式:

第一行依次为三个整数n, beginLevel, maxLevel。

第二行依次为n个整数 c1,c2,c3,...,cn。

数据规模:

1<=n<=50, 1<=ci<=maxLevel, 1<=maxLevel<=1000, 0<=beginLevel<=maxLevel

输出格式:

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

输入输出样例

输入样例#1:
复制

3 5 10
5 3 7
输出样例#1: 复制

10

设 dp[ i ][ j ]表示前 i 次后是否可以到达 j 音量,如果可以,则 dp[ i ][ j ]=1;
最后从maxx遍历,如果 dp[ n ][ j ]=1,输出 j 即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
} int n;
int bgin;
int maxx; int a[maxn];
int dp[2000][2000]; int main()
{
//ios::sync_with_stdio(0);
rdint(n);
rdint(bgin); rdint(maxx);
for (int i = 1; i <= n; i++)rdint(a[i]);
dp[0][bgin] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= maxx; j++) {
if (dp[i - 1][j] && j + a[i] <= maxx)dp[i][j + a[i]] = 1;
if (dp[i - 1][j] && j - a[i] >= 0)dp[i][j - a[i]] = 1;
}
}
for (int i = maxx; i >= 0; i--) {
if (dp[n][i]) { cout << i << endl; return 0; }
}
cout << -1 << endl;
return 0;
}

[HAOI2012]音量调节 BZOJ2748 dp的更多相关文章

  1. [luoguP1877] [HAOI2012]音量调节(DP)

    传送门 绝世傻DP #include <cstdio> #include <iostream> #define N 51 int n, s, mx; bool f[N][100 ...

  2. bzoj-2748 2748: [HAOI2012]音量调节(dp)

    题目链接: 2748: [HAOI2012]音量调节 Time Limit: 3 Sec  Memory Limit: 128 MB Description 一个吉他手准备参加一场演出.他不喜欢在演出 ...

  3. [bzoj2748][HAOI2012]音量调节_动态规划_背包dp

    音量调节 bzoj-2748 HAOI-2012 题目大意:有一个初值,给你n个$\delta$值,求最后不超过给定的限制的情况下的改变的最大值.每个$\delta$值可以+也可以-. 注释:$1\l ...

  4. BZOJ 2748: [HAOI2012]音量调节 dp

    2748: [HAOI2012]音量调节 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  5. BZOJ 2748: [HAOI2012]音量调节【二维dp,枚举】

    2748: [HAOI2012]音量调节 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2010  Solved: 1260[Submit][Statu ...

  6. bzoj2748: [HAOI2012]音量调节(背包)

    2748: [HAOI2012]音量调节 题目:传送门 题解: sb省选题..呵呵一眼背包: f[i][j]表示第i时刻能否为音量j 代码: #include<cstdio> #inclu ...

  7. Bzoj 2748: [HAOI2012]音量调节 动态规划

    2748: [HAOI2012]音量调节 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1234  Solved: 777[Submit][Status ...

  8. bzoj 2748: [HAOI2012]音量调节

    2748: [HAOI2012]音量调节 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 872  Solved: 577[Submit][Status] ...

  9. 到达型01背包---P1877 [HAOI2012]音量调节

    P1877 [HAOI2012]音量调节 题解 solution 1 普通dfs  60pt dfs 暴搜,pos 记录当前到了第几首歌,level 记录当前的音量 一个小剪枝 由于每换一首歌都要调节 ...

随机推荐

  1. Celery-4.1 用户指南:Testing with Celery (用 Celery测试)

    任务与单元测试 在单元测试中测试任务行为的推荐方法是用mocking. Eager mode: task_always_eager 设置启用的 eager 模式不适用于单元测试. 当使用eager模式 ...

  2. 2015.1.15 利用Oracle函数返回表结果 重大技术进步!

    -- sql 调用 select * from table( get_airway_subpoint(x,x,x)) ///////////////////////////////////////// ...

  3. Bytes和bits的区别(字节和位的区别)

    基本概念 Bit意为“位”或“比特”,是计算机运算的基础,属于二进制的范畴: Byte意为“字节”,是计算机文件大小的基本计算单位: 这两者应用的场合不同.通常用bit来作数据传输的单位,因为物理层, ...

  4. ztree 树的模糊搜索

    (转载),有个坑记录下: (原文)实现类似下面这种: /** * 展开树 * @param treeId */ function expand_ztree(treeId) { var treeObj ...

  5. linux 内核移植和根文件系统的制作

    1.1 Linux内核基础知识 在动手进行Linux内核移植之前,非常有必要对Linux内核进行一定的了解,下面从Linux内核的版本和分类说起. 1.1.1  Linux版本 Linux内核的版本号 ...

  6. ps和ai的一些认识

    ps主要是一个后期软件,它很大程度上不是一个创作型的软件,这是它的定位.我觉得李涛老师那句话说的很好,ps是对已有的素材进行加工的.这个已有的素材来源包括但不限于拍照.扫描.数绘板.下载的.如果说你想 ...

  7. 算法Sedgewick第四版-第1章基础-013一用stack实现自动补全表达式括号

    package algorithms.exercise; import algorithms.ADT.Stack; import algorithms.util.StdIn; import algor ...

  8. Bulma 源码解析之 .container 类

    Bulma 的 .container 类是这样实现的. .container position: relative // 不设置桌面以下设备的 container +desktop margin: 0 ...

  9. 《Effective Java》第8章 通用程序设计

    第47条:了解和使用类库 Top 100 Java Libraries on Github 2016 Library Number of Projects Type % of projects jun ...

  10. 关于webapi练习过程中遇到的一系列问题记录

    最近在尝试本地进行webapi调用的过程中,遇到一系列的问题,demo很小但着实让人头疼,先附上demo. 前台页面,目的是展示新闻的分类: 类别模型如下: 控制器代码如下: public Actio ...