(UVA
来源:互联网 发布:房屋设计图平面图软件 编辑:程序博客网 时间:2024/05/17 09:21
链接: https://vjudge.net/problem/UVA-11400
分析:先按电压从小到大排序,预处理求出1到i的数量和s[i],然后设dp[i] : 灯泡1到i的最小费用
状态转移方程: dp[0]=0;
dp[i]=min(dp[i],dp[j]+p[i].c*(s[i]-s[j])+p[i].k),j
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define mem(a,n) memset(a,n,sizeof(a))const int INF=0x3f3f3f3f;const int N=1e3+5;struct Node{ int v,k,c,l; bool operator < (const Node& m)const { return v<m.v; }} p[N];int s[N],dp[N];int main(){ int n; while(~scanf("%d",&n)&&n) { for(int i=1; i<=n; i++) scanf("%d%d%d%d",&p[i].v,&p[i].k,&p[i].c,&p[i].l); sort(p+1,p+n+1); s[0]=0; for(int i=1; i<=n; i++) s[i]=s[i-1]+p[i].l; mem(dp,INF); dp[0]=0; for(int i=1; i<=n; i++) for(int j=0; j<i; j++) { dp[i]=min(dp[i],dp[j]+p[i].c*(s[i]-s[j])+p[i].k); // printf("%d %d %d %d\n",p[i].c,p[i].k,s[i],s[j]); // printf("dp[%d]=%d\n",i,dp[i]); } printf("%d\n",dp[n]); } return 0;}
阅读全文
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 使用Scikit-learn实现基于内存的协同过滤算法(使用movieLens数据集)
- 上帝造题的7分钟2
- centos7 安装mysql步骤
- idea 创建java web项目(maven管理的SSH)
- 字典树模板(数组实现和指针实现)
- (UVA
- bzoj 1632: [Usaco2007 Feb]Lilypad Pond SPFA
- 任务、进程、线程之间的区别
- openwrt各种奇怪问题总结(对C++依赖)
- POJ
- 关于ip
- 匈牙利游戏之A*版
- 随笔
- 栈与堆