poj2231 Moo Volume
来源:互联网 发布:深圳软件产业基地公司 编辑:程序博客网 时间:2024/06/17 08:20
原题:http://poj.org/problem?id=2231
思路: dp[i]表示前i个location的Volume值,将输入数字排序,根据规律推出转移方程:dp[i]=dp[i-1]+(i-1)*2*(a[i]-a[i-1]);
#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;int cmp(const void *a,const void *b){int aa=*(int*)a;int bb=*(int*)b;return aa-bb;}int main(){int n;while(~scanf("%d",&n)){ll sum=0;ll a[10010];ll dp[10010]={0};for(int i=1;i<=n;i++){scanf("%lld",&a[i]);}qsort(a+1,n,sizeof(a[0]),cmp);//for(int i=1;i<=n;i++)//{//printf("%lld ",a[i]);//}//printf("\n");for(int i=2;i<=n;i++){ll tmp=2*(a[i]-a[i-1]);dp[i]=dp[i-1]+(i-1)*tmp;sum=sum+dp[i];}printf("%lld\n",sum);}return 0;}
阅读全文
0 0
- Poj2231 Moo Volume
- poj2231 Moo Volume
- POJ2231 Moo Volume [简单dp]
- Moo Volume
- Moo Volume
- Moo Volume
- Moo Volume
- poj 2231 Moo Volume
- openjudge-Moo Volume
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- 1633: Moo Volume
- POJ 2231 Moo Volume
- POJ -- 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231Moo Volume
- Atitit 防止迟到与防止打卡打不上解决方案 attilax总结
- “信息瓶颈”理论揭示深度学习本质
- Viewpager和RadioGroup实现联动
- Linux下OpenGL的安装与cmake编译OpenGL程序
- 再论单子的性质
- poj2231 Moo Volume
- Atitit 安全规范 指南 常见五种意外防止规范 attilax总结
- xjoi奋斗群群赛12
- 【最短路&DP】BZOJ5047空间传送装置
- OpenCV之直方图均衡化
- 弹性盒模型 flex 方法总结
- Java ArrayList的实现原理及源码解析
- Java入门(定期修改)
- SpringMVC 框架学习指南