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的更多相关文章

  1. 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 ...

  2. 【HDOJ】1500 Chopsticks

    DP. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm ...

  3. 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个数时的所求的最小值 ...

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  6. HDU 4278 Faulty Odometer 8进制转10进制

    Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  7. hdu 5268 ZYB loves Score 水题

    ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  8. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  9. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

随机推荐

  1. ORA-16014报错解决

    今天在本地数据库操作的时候报错: SQL> alter database open;alter database open*第 1 行出现错误:ORA-16014: 日志 3 的序列号 55 未 ...

  2. LeetCode_Word Ladder

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  3. IOS回调机制——代理,通知中心以及Block

    Xcode5.0正式版 IOS7和Xcode5正式版在昨天正式可以下载.IOS7不多说了,交互设计,界面风格,操作的简化程度都属于比较领先的水平. 这里来说说Xcode5正式版,和以前的Xcode5测 ...

  4. 工具:BT Sync 同步文件

    随着互联网的发展,文件共享变得越来越便捷,但是文件的共享过程是不是安全,这一直是人们关心的问题,今天向大家介绍一个共享工具,可以实现便捷的安全共享.      这个工具分为两个部分,一个是服务器部分, ...

  5. softlayer virtual machine vhd磁盘镜像导入shell脚本

    脚本

  6. JSP 中 JSTL 页面标签的笔记

    jsp头部引入使用的标签 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&g ...

  7. debian下编译libev库

    系统为Linux debian 2.6.32-5-686.这是裸系统,连xwindows都没有.帐户为root,不是的注意一下权限.这里想说明安装过程及出现的问题,故打印的信息较多,以供出现错误的读者 ...

  8. js 写table 函数

    //创建 table函数 function table(row,col,b,w) { document.write('<table border='+b+'>'); for(var i=0 ...

  9. Linux入门基础 #8:Linux拓展权限

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  10. CGContextRef CIImageRef详解

    第一种 先用UIImage对象加载一张图片 然后转化成CGImageRef放到CGContext中去编辑 第二种 用CGImageCreate函数创建CGImageRef 然后把CGImageRef放 ...