hdu 1500 Chopsticks
http://acm.hdu.edu.cn/showproblem.php?pid=1500
dp[i][j]为第i个人第j个筷子。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int dp[][];
int a[];
int k,n;
int sqr(int x)
{
return x*x;
}
bool cmp(const int a,const int b)
{
return a>b;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&k,&n);
memset(dp,,sizeof(dp));
memset(a,,sizeof(a));
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
sort(a+,a+n+,cmp);
k=k+;
for(int i=; i<=k; i++)
{
dp[i][i*]=dp[i-][i*-]+sqr(a[i*-]-a[i*]);
for(int j=i*+; j<=n; j++)
{
dp[i][j]=min(dp[i][j-],dp[i-][j-]+sqr(a[j-]-a[j]));
}
}
printf("%d\n",dp[k][n]);
}
return ;
}
hdu 1500 Chopsticks的更多相关文章
- hdu 1500 Chopsticks DP
题目链接:HDU - 1500 In China, people use a pair of chopsticks to get food on the table, but Mr. L is a b ...
- 【HDOJ】1500 Chopsticks
DP. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm ...
- hdu 1500 dp
/* 状态转移方程式: dp[i][j]=Min(dp[i][j-1],dp[i-1][j-2]+(a[j-1]-a[j])*(a[j-1]-a[j])); 依次求出第i个人在第j个数时的所求的最小值 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 4278 Faulty Odometer 8进制转10进制
Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- hdu 5268 ZYB loves Score 水题
ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
随机推荐
- 《Programming WPF》翻译 第6章 3.二进制资源
原文:<Programming WPF>翻译 第6章 3.二进制资源 尽管ResourceDictionary和系统级别的资源适合于作为数据存在于对象中,然而,并不是所有的资源都能很好的满 ...
- logstash 防止实际处理时间跟事件产生时间略有偏差
"message" => " 10.168.255.134 [12/Sep/2016:16:30:40 +0800] \"GET /resources/p ...
- ofbiz ins
- mysql常用操作命令
本章内容:(引用原文:http://www.cnblogs.com/suoning/p/5769141.html) 查看\创建\使用\删除 数据库 用户管理及授权实战 局域网远程连接法 查看\创建\使 ...
- CAS原理与协议
SSO英文全称Single Sign On,单点登录. SSO是在多个应用系统中,用户仅仅须要登录一次就能够訪问全部相互信任的应用系统. SSO的解决方式非常多,比方收费的有UTrust.惠普灵动等, ...
- 使用Reporting Service订阅对域外用户发邮件
默认情况下使用Reporting Service对域外邮件发送会失败,一般可能会碰到下面的两个错误: ERROR 1: Subscription Error: "The e-mail add ...
- Linux文件权限管理
一.设置文件所属的用户以及所属的组(chown,chgrp) chgrp用来更改文件的组拥有者,其一般格式为:chgrp [option] group file(1)把文件test的组拥有者改为zfs ...
- [Python学习笔记][第六章Python面向对象程序设计]
1月29日学习内容 Python面向对象程序设计 类的定义与使用 类定义语法 使用class关键词 class Car: def infor(self): print("This is ca ...
- DE2带的IP核ISP12362报错问题解决 Error:avalon_slave_1_irq: associatedAddressablePoint out of range
问题来源与对友晶提供的ISP1362 IP核的使用,由于Quartus II版本问题,它提供的IP基于7.0版本,而我用的版本为11.1,在SOPC Builder中重新加载IP,就出现了上述的错误报 ...
- C# Datatable导出Excel方法
C# 导出Excel方法 先引用下System.IO;System.data; 具体函数如下: public static bool ExportCSV(DataTable dt, string f ...