博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[luoguP1877] [HAOI2012]音量调节(DP)
阅读量:4597 次
发布时间:2019-06-09

本文共 709 字,大约阅读时间需要 2 分钟。

 

绝世傻DP

 

#include 
#include
#define N 51int n, s, mx;bool f[N][1001];inline int read(){ int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1; for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f;}int main(){ int i, j, k, x; n = read(); s = read(); mx = read(); f[0][s] = 1; for(i = 1; i <= n; i++) { x = read(); for(j = 0; j <= mx; j++) { if(j + x <= mx && f[i - 1][j]) f[i][j + x] = 1; if(j - x >= 0 && f[i - 1][j]) f[i][j - x] = 1; } } for(i = mx; i >= 0; i--) if(f[n][i]) { printf("%d\n", i); return 0; } puts("-1"); return 0;}

  

转载于:https://www.cnblogs.com/zhenghaotian/p/7308834.html

你可能感兴趣的文章
正式退役
查看>>
退役后做题记录
查看>>
gdsoi2019题解
查看>>
003_Python3 基本数据类型
查看>>
iis7 应用程序池回收设置
查看>>
UVA 11375 - Matches
查看>>
python识别图中的文字(ocr)
查看>>
教你一眼认出英语单词的意思
查看>>
squid使用NCSA验证
查看>>
黑马程序员----java基础--String字符串
查看>>
BT.601与BT.656
查看>>
采用FPGA实现多种类型的数字信号处理滤波器
查看>>
专家支招:使用MATLAB和Simulink算法创建FPGA原型
查看>>
Go语言最佳实践——异常和错误
查看>>
Tracer使用
查看>>
ORA-00600 3020 ORA-10567案例
查看>>
Spring Batch Hello World Example(一)
查看>>
Robot Framework web测试demo
查看>>
php不用正则表达式获取文章A标签链接的方法
查看>>
doubango框架阅读计划
查看>>