标签:des style http color io os ar for sp
6 3 5 9 12 15 17 6 3 5 9 12 30 40
3 -1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
const int INF=0x3f3f3f;
const int maxn=1e5+100;
int dp[maxn][15];
int hash[10*maxn];
int num[maxn],n;
int main()
{
while(~scanf("%d",&n)&&n)
{
memset(dp,INF,sizeof(dp));
memset(hash,-1,sizeof(hash));
for(int i=1;i<=n;i++)
{
scanf("%d",&num[i]);
hash[num[i]]=i;
}
dp[2][num[2]-num[1]]=0;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=10;j++)
{
if(j>num[i]) break;
for(int k=j+1;k<=10;k++)
{
int tt=num[i]-j;
if(hash[tt]>=0)
dp[i][j]=min(dp[hash[tt]][k-j]+1,dp[i][j]);
}
}
}
int ans=INF;
for(int i=1;i<=10;i++)
// {
// cout<<"1111 "<<dp[n][i]<<endl;
ans=min(ans,dp[n][i]);
// }
if(ans<INF) printf("%d\n",ans);
else printf("-1\n");
}
return 0;
}
标签:des style http color io os ar for sp
原文地址:http://blog.csdn.net/u013582254/article/details/39852935