1294:Charm Bracelet

简介: 1294:Charm Bracelet

时间限制: 1000 ms         内存限制: 65536 KB

【题目描述】

经典0—1背包问题,有n个物品,编号为i的物品的重量为w[i],价值为c[i],现在要从这些物品中选一些物品装到一个容量为m的背包中,使得背包内物体在总重量不超过m的前提下价值尽量大。

【输入】

第1行:两个整数,n(物品数量,n≤3500)和m(背包容量,m≤12880)。

第2..n+1行::每行二个整数w[i],c[i],表示每个物品的重量和价值。

【输出】

仅一行,一个数,表示最大总价值。

【输入样例】

4 6

1 4

2 6

3 12

2 7

【输出样例】

23

1. #include <iostream>
2. #include <cstdio>
3. #include <cstring>
4. #include <algorithm>
5. using namespace std;
6. int f[12900];
7. int n,m,w,c;
8. int main(int argc, char *argv[])
9. {
10.   scanf("%d %d",&n,&m);
11.   for(int i=1;i<=n;i++){
12.     scanf("%d %d",&w,&c);
13.     for(int j=m;j>=w;j--)
14.       f[j]=max(f[j],f[j-w]+c);
15.   }
16.   printf("%d\n",f[m]);
17.   return 0;
18. }
相关文章
|
9月前
|
JavaScript
鬼火起~为什么报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the
鬼火起~为什么报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the
|
6月前
|
开发工具 git
Stylelint——Unexpected unknown pseudo-class selector ":deep" selector-pseudo-class-no-unknown
新项目制定规范接入了stylelint,并通过husky在git提交时去触发检测修复,使用`:deep()`的时候却发现了报错;
232 1
|
9月前
|
小程序 JavaScript
Avoid mutating a prop directly since the value will be overwritten whenever the parent comp
Avoid mutating a prop directly since the value will be overwritten whenever the parent comp
|
Kubernetes Docker 容器
Kubernetes分享-ImagePullBackOff Error的trouble shooting
Kubernetes分享-ImagePullBackOff Error的trouble shooting
325 0
|
Android开发
【Solve】InnerClass annotations are missing corresponding EnclosingMember annotations. Such InnerClass annotations are ignored
【Solve】InnerClass annotations are missing corresponding EnclosingMember annotations. Such InnerClass annotations are ignored
143 0
【Solve】InnerClass annotations are missing corresponding EnclosingMember annotations. Such InnerClass annotations are ignored
|
机器学习/深度学习
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
133 0
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
97 0
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
PKU 3624 Charm Bracelet
本文主要讲背包入门题
101 0
|
JavaScript
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px '.SF NS Text'} No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing instance of type SmsUtils (e.g. x.new A() where x is an instance of SmsUtils). 今天在写一个短信发送的工具类时使用到了内部类,在实例化内部类时遇到此错误。
1468 0