http://blog.youkuaiyun.com/now_ing/article/details/78148715
以下自己的AC代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll dp[100005];
ll a[100005];
int main()
{
int n;
memset(dp,0,sizeof(dp));
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
dp[0]=a[0];
dp[1]=a[1];
for(int i=2;i<n;i++)
{
dp[i]=min(dp[i-1]+a[0]+a[i],dp[i-2]+a[0]+a[1]*2+a[i]);
}
printf("%lld\n",dp[n-1]);
return 0;
}

本文提供了一段AC代码,通过动态规划解决了一个特定的问题。代码使用C++编写,包括了必要的头文件,并定义了用于存储动态规划状态的数组。通过对输入数据的排序和最小值选择实现了最优解。
5454

被折叠的 条评论
为什么被折叠?



