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. ubuntu 执行apt-get update 提示无法获得锁

    问题如下: y@y:~$ sudo apt-get updateE: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)E: 无法对目录 /var/l ...

  2. Win8.1专业版、核心板和企业版有什么区别

    Win8.1核心版(一般就称之为Windows 8.1) + Win8.1 专业版(称之为Windows 8.1 Pro),根据用户输入的序列号(就是Win8密钥)来区分安装.Win8.1企业版(称之 ...

  3. 查看当前发行版可以使用的shell

    查看当前发行版可以使用的shell [root@localhost ~]$ cat /etc/shells/bin/sh/bin/bash/sbin/nologin

  4. highchart 实现mrtg

    最近需要对流量图进行重构, <%@ page language="java" contentType="text/html; charset=UTF-8" ...

  5. VS 项目(c#)引用了 DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称

    1. 在项目上点右键-->属性-->应用程序-->目标框架-->修改为.NET Framework 4. 而我原来的设置是.NET Framework 4 Client Pro ...

  6. pyQt事件处理

    Qt事件处理01 Qt处理事件的第二种方式:"重新实现QObject::event()函数",通过重新实现event()函数,可以在事件到达特定的事件处理器之前截获并处理他们.这种 ...

  7. classloader.getresources() 介绍

    ◆普通情况下,我们都使用相对路径来获取资源,这种灵活性比較大. 比方当前类为com/bbebfe/Test.class 而图像资源比方sample.gif应该放置在com/bbebfe/sample. ...

  8. [Regular Expressions] Find Groups of Characters, and ?:

    We'll capture groups of characters we wish to match, use quantifiers with those groups, and use refe ...

  9. rz/sz上传下载

    z(Zmodem文件传输协议) rz  文件上传(Receive Zmodem)  rz sz  文件下载(Send Zmodem)  sz filename rz/sz工具需要自己安装

  10. Oracle中drop user和drop user cascade的区别

    drop user : 仅仅是删除用户,drop user username cascade :会删除此用户名下的所有表和视图. userSpecify the user to be dropped. ...