hdu 1500 Chopsticks DP
题目链接:HDU - 1500
It's
December 2nd, Mr.L's birthday! He invited K people to join his birthday
party, and would like to introduce his way of using chopsticks. So, he
should prepare K+8 sets of chopsticks(for himself, his wife, his little
son, little daughter, his mother, father, mother-in-law, father-in-law,
and K other guests). But Mr.L suddenly discovered that his chopsticks
are of quite different lengths! He should find a way of composing the
K+8 sets, so that the total badness of all the sets is minimized.
first line in the input contains a single integer T, indicating the
number of test cases(1<=T<=20). Each test case begins with two
integers K, N(0<=K<=1000, 3K+24<=N<=5000), the number of
guests and the number of chopsticks. There are N positive integers Li on
the next line in non-decreasing order indicating the lengths of the
chopsticks.(1<=Li<=32000).
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int k,n,num[maxn];
int dp[+][maxn]; int main()
{
int t;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&k,&n);
for (int i=n ;i>= ;i--) scanf("%d",&num[i]);
k += ;
memset(dp,,sizeof(dp));
for (int i= ;i<=k ;i++)
{
dp[i][*i]=dp[i-][*i-]+(num[*i-]-num[*i])*(num[*i-]-num[*i]);
for (int j=*i+ ;j<=n ;j++)
dp[i][j]=min(dp[i][j-],dp[i-][j-]+(num[j-]-num[j])*(num[j-]-num[j]));
}
printf("%d\n",dp[k][n]);
}
return ;
}
hdu 1500 Chopsticks DP的更多相关文章
- hdu 1500 Chopsticks
http://acm.hdu.edu.cn/showproblem.php?pid=1500 dp[i][j]为第i个人第j个筷子. #include <cstdio> #include ...
- hdu 4123 树形DP+RMQ
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
随机推荐
- (笔记) RealTimeRender[实时渲染] C3
@author: 白袍小道 转载表明,查看随缘 前言: 从历史上看,图形加速始于每个像素扫描线上的插值颜色重叠一个三角形,然后显示这些值.包括访问图像数据允许纹理应用于表面.添加硬件 插入和测试z深度 ...
- Scrapy爬取到的中文数据乱码问题处理
Scrapy爬取到中文数据默认是 Unicode编码的,于是显示是这样的: "country": ["\u56fd\u4ea7\u6c7d\u8f66\u6807\u5f ...
- 电脑显卡4种接口类型:VGA、DVI、HDMI、DP
电脑显卡全称显示接口卡(Video card,Graphics card),又称为显示适配器(Video adapter),显示器配置卡简称为显卡,是个人电脑最基本组成部分之一.对于显卡接口类型,主要 ...
- 网络--OSI七层模型详解
OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...
- UVa 1445 - Cubist Artwork
统计正面看高度为i的竖条个数为cnt1[i], 统计侧面看高度为i的竖条个数为cnt2[i]: ans = sum( i * max( cnt1[i], cnt2[i] ) ); ( 1 <= ...
- stuff使用感悟
select ),t2.CityId) from t t2 where not exists( from Web_UserCity uc where UserName='user001' and uc ...
- Hexo安装和配置
Hexo安装和配置 1. Git安装和设置 github brew install git #Mac电脑使用brew安装 sudo apt-get install git #Ubuntu系统使用这 ...
- KVC 开发详情
目录 概述 KVC基本技术 KVC访问函数 KVC搜索顺序 KVC集合操作 一.概述 kvc全名是Key-value coding,kvc是一种通过字符串间接的访问oc对象的属性的一种技术. 一个oc ...
- iOS大神班笔记02-模仿苹果创建单例
首先我们得要知道苹果是如何实现单例的:1.不能外界调用alloc,一调用就崩掉,其实就是抛异常(类内部第一次调用alloc就不崩溃,其他都崩溃). 2.提供一个方法给外界获取单例. 3.内部创建一次 ...
- python登录qq
登录qq的用的是get方法, 首先抓login_sig(某个包中的cookie),接着验证码的包(包含对验证码的校验),,最后计算一个p的加密算法,接着再get请求一个链接 https://ssl.p ...