UValive4195 Heroes of Money and Magic
斜率优化
想骂人了,马格吉最后调了半小时
TMD造数据的人是SB吧?
我写 while(scanf("%d%d",&n,&m)!=EOF&&n)
然后就TMD无限WA...WA...WA...
尼玛 改成while(scanf("%d%d",&n,&m),n)
就过了,就过了!!!
沃日,浪费我时间是吧,坑爹是吧
艹
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<cstring>
#define Clear(x,i) memset(x,i,sizeof(x))
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
template <typename Q>
void inin(Q &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
ret=f?-ret:ret;
}
int n,m,a[],sum[],cost[],x[][],y[][],num[];
int f[][],c;
int cross(int a,int b,int xx,int yy)
{
return (x[b][c]-x[a][c])*(yy-y[a][c])-
(xx-x[a][c])*(y[b][c]-y[a][c]);
}
int main()
{
while(scanf("%d%d",&n,&m),n)
{
m++;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
cost[i]=cost[i-]+sum[i-]*a[i];
}
num[]=;
c=;
x[][]=y[][]=;
for(int j=;j<=m;j++)
{
c^=;
num[c]=;
for(int i=,k=;i<=n;i++)
{
while(k<num[!c]&&(x[k+][!c]-x[k][!c])*sum[i]>y[k+][!c]-y[k][!c])k++;
f[i][c]=-sum[i]*x[k][!c]+y[k][!c]+cost[i];
int xx=sum[i],yy=f[i][c]+xx*xx-cost[i];
while(<num[c]&&cross(num[c]-,num[c],xx,yy)<=)num[c]--;
x[++num[c]][c]=xx;
y[num[c]][c]=yy;
}
}
printf("%d\n",f[n][c]);
}
return ;
}
UValive4195 Heroes of Money and Magic的更多相关文章
- 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02) H Heroes Of Might And Magic (隐含dp)
问题是求一个方案,实际隐含一个dp.法力是递减的,所以状态是DAG,对于一个确定的状态,我们贪心地希望英雄的血量尽量大. 分析:定义状态dp[i][p][h]表示是已经用了i的法力值,怪兽的位置在p, ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- 黑科技项目:英雄无敌III Mod <<Fallen Angel>>介绍
英雄无敌三简介(Heroes of Might and Magic III) 英3是1999年由New World Computing在Windows平台上开发的回合制策略魔幻游戏,其出版商是3DO. ...
- dp题目列表
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- [转] POJ DP问题
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ动态规划题目列表
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- 【nginx】解决Nginx重启时提示nginx: [emerg] bind() to 0.0.0.0:80错误
Nginx是一款轻量级的Web服务器,特点是占有内存少,并发能力强,因而使用比较广泛,蜗牛今天在一个VPS上重启Nginx时提示“nginx: [emerg] bind() to 0.0.0.0:80 ...
- 八、Sql Server 基础培训《进度8-查询多种写法》(实际操作)
知识点: 假设学生表.班级表.年级表 学生表(student) 内码 学生姓名 班级内码 001 张三 1002 002 李四 1002 003 王五 1003 004 钱六 1001 班级表(cla ...
- Java课程寒假之开发记账本软件(网页版)之四
一.实现基础功能之一(删除) 在删除的功能实现之前,要明白删除的条件是什么,一开始我是以去向和时间作为条件删除,但是删除的语句好像有问题,好像是因为出现了非法字符(应该是中文吧,不太清楚,因为这不是我 ...
- Tcp/IP 的四层模型
维基:https://zh.wikipedia.org/wiki/TCP/IP%E5%8D%8F%E8%AE%AE%E6%97%8F 因特网协议组 LITA 因特网协议组 Link 网络接口层 以太 ...
- pythonic operations
变量交换 >>> a, b = b, a 循环遍历区间元素 >>>for i in range(10): ... print (i) 返回的是生成器对象,生成器比列 ...
- MySQL数据库(查询语句)
用户 角色 权限 select * from students1:查询这个表里的数据 select ssex from students1:在这个表里面查询ssex(性别) select dist ...
- Oracle实验手册
oracle安装 安装virtualbox: # yum install gcc kernel-devel kernel-headers # yum install virtualbox-5.... ...
- C++关于运算符重载知识点
1) 除了类属关系运算符".".成员指针运算符".*".作用域运算符"::".sizeof运算符和三目运算符"?:"以外 ...
- 常用oracle hints
在SQL语句优化过程中,经常会用到hint, 以下是在SQL优化过程中常见Oracle中"HINT"的30个用法 1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方 ...
- mongodb 使用mongodump备份 指定用户名密码 出现错误 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed
mongodb 使用mongodump备份 指定用户名密码 出现错误 [root@MongoDB ~]# mongodump --host -u admin -p -d db1 -o /root/ F ...