UVA 11400
来源:互联网 发布:python余弦相似度 编辑:程序博客网 时间:2024/05/29 08:10
基础的线性dp,紫书上的例题。
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#define LL long long#define ull unsigned long long#define FOR(i,x,y) for(int i=x;i<=y;i++)using namespace std;const int maxn = 1000 + 10;const int INF = 100000000;struct Light{int V;int K;int C;int L;}lights[maxn];int dp[maxn];int N;bool cmp(const Light A , const Light B){return A.V < B.V;}int s[maxn];int main(){while(cin>>N && N){FOR(i,1,N) cin>>lights[i].V>>lights[i].K>>lights[i].C>>lights[i].L;sort(lights+1,lights+1+N,cmp);memset(dp,0,sizeof(dp)); FOR(i,1,N) s[i] = s[i-1] + lights[i].L;//FOR(i,1,N) // dp[i] = dp[i-1] + lights[i].L * lights[i].C + lights[i].K;FOR(i,1,N){int res = INF;FOR(j,0,i-1) res = min(res,dp[j]+(s[i]-s[j])*lights[i].C+lights[i].K);dp[i] = res;}cout<<dp[N]<<endl;}return 0;}
0 0
- UVA 11400
- uva 11400
- UVa 11400
- uva 11400
- Uva 11400 照明系统
- UVA 11400(DP)
- UVA 11400 01背包
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- myBatis批量添加,修改和删除
- 一个非常好的网络验证系统
- Win7+Eclipse+Hadoop2.4.1+Lunx RedHat集群开发环境配置
- Jquery的DataTable插件 AJAX 服务器分页的的学习心得(java版)
- Application与Applet的区别
- UVA 11400
- VFP 学习、开发漫谈 (27)- 权限管理
- PEAW简介
- swift语言初见
- hdu 4865
- 纯css绘制三角形
- 智能技术与自然语言处理研究室
- poj 2528
- javaScript简单用户注册应用