记录编号 |
259219 |
评测结果 |
AAAAAAAAAA |
题目名称 |
筷子 |
最终得分 |
100 |
用户昵称 |
NewBee |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.024 s |
提交时间 |
2016-05-08 16:05:04 |
内存使用 |
0.28 MiB |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- #define Cu fclose(stdin);fclose(stdout);return 0
- #define Begin freopen("chop.in","r",stdin);freopen("chop.out","w",stdout);chul();Cu;
- using namespace std;
- //designed by New_Beeؼ
- const int maxn=110;
- int f[maxn][maxn>>1];
- int a[maxn];
- void chul();
- void top(int);
- int min(int,int);
- int main(){
- Begin;
- }
- void chul(){
- int n,m;scanf("%d%d",&n,&m);m+=3;
- for(int i=1;i<=n;i++){
- scanf("%d",&a[i]);
- }
- if(m*2>n){
- printf("-1");
- return;
- }
- top(n);
- for(int j=1;j<=m;j++){
- for(int i=j*2;i<=n;i++){
- f[i][j]=min(f[i][j],f[i-1][j]);
- int t=a[i]-a[i-1];
- f[i][j]=min(f[i][j],f[i-2][j-1]+t*t);
- }
- }
- printf("%d",f[n][m]);
- }
- void top(int n){
- memset(f,0x7f,sizeof(f));
- f[0][0]=0;
- for(int i=1;i<=n;i++){
- int x=0x7fffffff,p;
- for(int j=i;j<=n;j++){
- if(a[j]<x){
- x=a[j];
- p=j;
- }
- }
- int t=a[i];
- a[i]=x;
- a[p]=t;
- }
- }
- int min(int x,int y){
- if(x>y)return y;
- return x;
- }
- /*
- 10 1
- 1 1 2 3 3 3 4 6 10 20
- */