ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 E Eat Walnuts

2021-03-06 19:30:33  阅读:296  来源: 互联网

标签:int 45 walnut Watermelon ICPC Mr Walnuts walnuts define


传送门

E Eat Walnuts

As we all know, in the ACM ICPC held in 2017, the organizer of Xinjiang University presented a box of walnuts to each coach. Our coach is happy to share with the team members except Mr.Watermelon. He is going to test Mr.Watermelon with a game when Mr.Watermelon want to eat some walnuts.

He put some walnuts in a row and let Mr.Watermelon pick one of them. And this walnut is not the first or last in the queue. The price Mr.Watermelon need to pay is : the walnut, the walnut in front of the walnut, and the walnut behind the walnut , the square of the sum of the size of these three walnuts.

For example, now there is a row of walnuts in front of Mr.Watermelon. Their size is: 3 1 50 20 15. If this time Mr.Watermelon picked the third walnut. He needs to pay (1 + 50 + 20) ∗ (1 + 50 + 20) = 5041.

After a walnut is taken away, it will leave the queue. Then Mr.Watermelon picks a walnut again until only two walnuts remain in the queue.

Mr.Watermelon wants to know what the minimum price he will pay when he takes walnuts until there are only two walnuts in the queue. But he needs more time to spend with his girlfriend. So he ask you to help him calculate this problem.

最近这两天刷了,一个区间dp的题和这个题很类似,于是就想到这个题没补。。。。。

当时比赛的时候,没有什么特别的思路,队友想到了dfs,然后加上各种神奇剪枝,结果O(n!)。。。

有个地方得解释一下:比赛的时候以为题目中的左边的核桃,右边的核桃以为是相邻的,因此产生了歧义,实际上左边的核桃,右边的核桃,指的是最左边的核桃,和最右边的核桃。。。

#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
using namespace std;
const int mod=2001;
const int M=2e3+5;
const int N=4*1e2+5;//?????????? 4e8
int f[N][N];
int n,a[N];
int get(int x)
{
	return x*x;
}
void solve()
{
	while(cin>>n)
	{
		memset(f,0x3f,sizeof(f));
		for(int i=0;i<N-1;i++)  f[i][i]=f[i][i+1]=0;
		for(int i=1;i<=n;i++)  scanf("%lld",&a[i]);
		for(int len=3;len<=n;len++)  for(int l=1;l<=n;l++)
		{
			int r=len+l-1;
			if(r>n)  continue;
			for(int k=l+1;k<r;k++)  f[l][r]=min(f[l][r],f[l][k]+f[k][r]+get(a[l]+a[k]+a[r]));
		}
		cout<<f[1][n]<<endl;
	}
	
}
signed main()
{
//	ios::sync_with_stdio(false);
	solve();
	return 0;
}

标签:int,45,walnut,Watermelon,ICPC,Mr,Walnuts,walnuts,define
来源: https://blog.csdn.net/lcl1234567890lcl/article/details/114452532

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有