bzoj2748音量调节——背包
2024-09-05 13:04:05
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2748
怎么会有这样的省选题...
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,st,mx,c[];
bool f[][];
int main()
{
scanf("%d%d%d",&n,&st,&mx);
for(int i=;i<=n;i++)scanf("%d",&c[i]);
f[][st]=;
for(int i=;i<=n;i++)
for(int j=;j<=mx;j++)
{
if(j+c[i]<=mx)f[i][j]|=f[i-][j+c[i]];
if(j-c[i]>=)f[i][j]|=f[i-][j-c[i]];
}
int ans=-;
for(int j=mx;j>=;j--)
if(f[n][j])
{
ans=j;break;
}
printf("%d",ans);
return ;
}
最新文章
- mysql概要(十三)备份和恢复
- topcoder 673
- remastersys修改默认选项
- java集合——进度1
- ionic ion-list 滑到底部自动加载数据案例
- 卷积神经网络(CNN)前向传播算法
- iOS开发之单例模式
- 1.0、Android Studio管理你的项目
- ES6的let
- python--第十三天总结(html ,css 语法)
- Newtonsoft的序列化和反序列化
- mysql5.7报err 1055错误 sql_mode=only_full_group_by
- WPF手动绑定事件
- 00013 - top命令详解
- [python] os.path模块常用方法汇总
- Delphi应用程序的调试(四)The Debug Inspector
- js中函数传参的情况
- I.MX6 eMMC 中启动U-boot存放的首地址
- 获取当前路径下的所有文件路径 :listFiles
- eslasticsearch操作集锦