[HAOI 2012]音量调节
2017-11-05 15:40
411 查看
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 105 3 7
Sample Output
10HINT
1<=N<=50,1<=Ci<=Maxlevel 1<=maxlevel<=10000<=beginlevel<=maxlevel
题解
自古蛤省出水题。拿个$bool$背包乱搞一下就好了。没事干还可以滚一下。//It is made by Awson on 2017.11.5 #include <set> #include <map> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define Min(a, b) ((a) < (b) ? (a) : (b)) #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Abs(x) ((x) < 0 ? (-(x)) : (x)) using namespace std; const int N = 50; const int M = 1000; bool f[M+5][N+5], t, lt; int n, b, m, c; void work() { scanf("%d%d%d", &n, &b, &m); t = 1; f[b][lt] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &c); for (int j = 0; j <= m; j++) { f[j][t] = 0; if (j-c >= 0) f[j][t] |= f[j-c][lt]; if (j+c <= m) f[j][t] |= f[j+c][lt]; } swap(t, lt); } for (int i = m; i >= 0; i--) if (f[i][lt]) { printf("%d\n", i); return; } printf("%d\n", -1); } int main() { work(); return 0; }
相关文章推荐
- [HAOI2012] 音量调节
- bzoj2748 [HAOI2012]音量调节
- bzoj2748: [HAOI2012]音量调节
- bzoj2748 [HAOI2012]音量调节(dp水)
- [luoguP1877] [HAOI2012]音量调节(DP)
- P1877 [HAOI2012]音量调节
- [HAOI2012]音量调节
- BZOJ2748 [HAOI2012]音量调节
- BZOJ 2748: [HAOI2012]音量调节( dp )
- bzoj2748:[HAOI2012]音量调节
- [HAOI2012]音量调节
- bzoj 2748: [HAOI2012]音量调节
- [HAOI2012]音量调节
- 【动态规划】【记忆化搜索】【dfs】bzoj2748 [HAOI2012]音量调节
- Luogu P1877 [HAOI2012]音量调节
- BZOJ 2748: [HAOI2012]音量调节
- [BZOJ][HAOI2012][背包DP]音量调节
- [BZOJ 2748][HAOI2012]音量调节
- luogu P1877 [HAOI2012]音量调节
- BZOJ2748 [HAOI2012]音量调节(洛谷P1877)