背包问题
来源:互联网 发布:内蒙广电网络登录入口 编辑:程序博客网 时间:2024/05/24 11:14
题目链接:51Nod 1085
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int V = scanner.nextInt(); int[] c = new int[N]; int[] v = new int[N]; for(int i = 0; i < N; i++) { c[i] = scanner.nextInt(); v[i] = scanner.nextInt(); } int[] f = new int[V+1]; for(int i =0 ; i < N; i++) { for(int j = V; j >= c[i]; j--) { f[j] = Math.max(f[j], f[j-c[i]] + v[i]); } } System.out.println(f[V]); }}
阅读全文
0 0
- 【无限背包】背包问题
- 背包问题---01背包
- 背包问题--部分背包
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- java-File-mkdir与createNewFile的先后执行
- Target Sum
- 创建和销毁对象
- Redis自带的redis-benchmark使用
- 多线程同步 未完
- 背包问题
- android DrawerLayout 点击穿透、点击自身消失等问题解决
- 花生壳原理
- Shell 函数
- AngularJs1 待续
- 求π的近似值(2)
- iptables--面试题
- docker 源码开发环境的创建
- react-native 屏幕尺寸和文字大小适配