June 11th 模拟赛C T4 Cleanup Solution
来源:互联网 发布:java刚培训工资 编辑:程序博客网 时间:2024/04/29 06:34
空降题目处
点我点我点我
Description:
有N(1<=N<=40000)个奶牛到FJ的餐厅吃饭,餐厅里有M(1<=M<=N)种菜,每头牛有自己喜欢的菜的编号P_i(1<=P_i<=M),每头牛只吃自己喜欢的这道菜。
牛儿们在外面排着队进来,按照排队顺序一批一批进来,每批可以同时进来任意头牛,每一批吃完(注意包括最后一批)都要进行打扫,如果这批牛中一共需要K种菜,那么吃完后的打扫时间为K*K。
请你帮助FJ如何安排各批次使得总打扫时间最少。
Input
第1行:空格隔开的两个整数N和M
第2到N+1行:第i+1行包含一个整数P_i。
Output
输出最少打扫时间。
Solution
又是一个神奇的DP.
使用了神奇的DP式.
已知
我们一起可以选
由此可知,
因此,我们可以这样做:
设
可得DP式:
那么问题来了,如何维护详见下面代码
范围:
初值: 详见下面代码
Program
uses math;var x,n,m,i,j,k,ml:longint; f,p,l:array [-1..40000] of longint;begin assign(input,'cleanup.in'); assign(output,'cleanup.out'); reset(input); rewrite(output); readln(n,m); ml:=trunc(sqrt(n))+1; fillchar(l,sizeof(l),255); readln(x); l[x]:=1; f[1]:=1; p[1]:=1; f[-1]:=maxlongint div 2; for i:=2 to n do begin readln(x); p[0]:=i; for j:=ml downto 1 do if l[x]<p[j] then p[j]:=p[j-1]; f[i]:=i; for j:=1 to ml do f[i]:=min(f[i],f[p[j]-1]+j*j); l[x]:=i; end; writeln(f[n]); close(input); close(output);end.
0 0
- June 11th 模拟赛C T4 Cleanup Solution
- June 11th 模拟赛C T1 Sandcas Solution
- June 11th 模拟赛C T2 Cowski Solution
- June 11th 模拟赛C T3 Cowski Solution
- July 14th 模拟赛C T4 开花 Solution
- July 16th 模拟赛C T4 奶牛排队 Solution
- December 10th 模拟赛C T4 二叉树 Solution
- June 11th 模拟赛B T1 刺杀大使 Solution
- June 11th 模拟赛B T2 翻山越岭 Solution
- July 15th 模拟赛C T4 回家(莫名其妙【推荐】) Solution
- September 17th 模拟赛PJ T4 稀有逛超市 Solution
- July 14th 模拟赛C T1 输油管道 Solution
- July 14th 模拟赛C T2 数码问题 Solution
- July 14th 模拟赛C T3 灌水 Solution
- July 15th 模拟赛C T1 游泳池 Solution
- July 15th 模拟赛C T2 积木游戏 Solution
- July 16th 模拟赛C T1 竞赛排名 Solution
- July 16th 模拟赛C T3 圆周舞蹈 Solution
- 游戏核心编程之一 概述
- 老鼠怕猫是鼻子决定的?!
- 游戏编程之二 windows编程基础
- 动物叫
- Andorid-----dialog弹出框 点击周围空白处弹出层不自动消失
- June 11th 模拟赛C T4 Cleanup Solution
- LeetCode OJ 61. Rotate List 考虑边界条件
- 游戏编程之三 DirectX SDK简介
- iOS _评论后返回上一页面显示最新评论数据
- 扩展欧几里德算法详解
- ps
- 游戏编程之四 diectxdarw基础篇
- 《如何变得有思想》读书笔记
- Solr入门之官方文档6.0阅读笔记系列(七)