搬运礼物
来源:互联网 发布:淘宝助理要收费 吗 编辑:程序博客网 时间:2024/04/29 13:15
http://codevs.cn/problem/3409/
n个礼物分K次搬运,一个搬a个价值W【A】 求最小价值。
一开始认为,将所有情况考虑出来:将N分为a1*num1+a2*num2+a3*num3……=n
min=min(min,num1*w[num1]+num2*w[num2]….);
再仔细一想纯粹扯淡,也没啥好的想法。
记忆化DP,从前面开始,将前面的最好的状态考虑好,慢慢向后走。
#include<iostream>#include<stdio.h>#include<cmath>#include<algorithm>using namespace std;int main(){ int a[5005] = { 0 }; int b[5005] = { 0 }; int n; cin >> n; for (int i = 1; i < n+1; i++) { scanf_s("%d",&a[i]); b[i] = 999999; } b[1] = a[1]; for (int i = 2; i < n+1; i++) { for (int j = 1; j <= i ; j++) b[i] = min(b[i], b[i - j] + a[j]); } cout << b[n] << endl; system("pause"); return 0;}
0 0
- 搬运礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 礼物
- 搬运啊搬运
- 资料搬运
- 收到礼物
- 许巍 "礼物"
- 一件礼物
- 还是礼物
- 圣诞礼物
- Android画图Path的使用
- Java--传参的值传递和引用传递问题
- c++中的函数 和 c 函数的不同
- [Android][Android Studio] *.jar 与 *.aar 的生成与*.aar导入项目方法
- [c]hdoj 1204 概率题
- 搬运礼物
- JAVA拾遗——基本语法,汇总及练习。
- O-C相关-06:对象与对象的关系
- Mysql连接查询
- linux 线程学习之条件变量
- ExtJS中FormPanel的labelWidth问题
- 从头开始学习算法和数据结构
- SPOJ QTREE2 Query on a tree II (倍增LCA)
- Mysql 多实例配置与启停