求一个最长的递减序列,要求长度,和不一样的解的个数
#define zout fout
#define debug
#define maxn 5020
using namespace std;
typedef long long Long;
ifstream fin("buylow.in");
ofstream fout("buylow.out");
struct bignum
{
int a[100];
int len;
void setNum(Long r)
{
memset(a,0,sizeof(a));
len=0;
while(r)
{
a[len++]=r%10;r/=10;
}
}
bignum()
{
len=0;
memset(a,0,sizeof(a));
}
bignum operator+(bignum b)
{
int ic=0,c=0,s;
for(int i=0;i<100;i++)
{
s=a[i]+b.a[i]+c;
a[i]=s%10;
c=s/10;
if(a[i])len=i+1;
}
return *this;
}
bool operator==(bignum b)
{
if(b.len!=len)return false;
for(int i=0;i<len;i++)
if(b.a[i]!=a[i])return false;
return true;
}
bool operator<(bignum b)
{
if(b.len>len)return true;
else if(b.len==len)
{
for(int i=len-1;i>=0;i--)
if(b.a[i]>a[i])return true;
}
return false;
}
void print()
{
for(int i=len-1;i>=0;i--)
zout<<a[i];
zout<<endl;
}
};
Long num[maxn];//
bignum mc[maxn];
int f[maxn];
int dp[maxn];
int n,next[maxn];
void init_next();
void init()
{
fin>>n;
Long temp;
for(int i=0;i<n;i++)
{
fin>>f[i];
}
init_next();
}
void slove()
{
/*
Long a,b;
bignum aa,bb;
while(cin>>a>>b)
{
aa.setNum(a);
bb.setNum(b);
if(aa<bb)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
*/
memset(dp,0,sizeof(dp));
int ans=0,temp;
for(int i=0;i<n;i++)
{
temp=0;
for(int j=0;j<i;j++)
{
if(f[j]>f[i]&&dp[j]>temp)
temp=dp[j];
}
dp[i]=temp+1;
ans=max(ans,dp[i]);
}
zout<<ans<<" ";
bignum one;
one.setNum(1);
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
if(f[j]>f[i])
{
if(dp[j]+1>dp[i])
mc[i]=mc[j];
else if(dp[j]+1==dp[i])
{
if(next[j]&&next[j]<i)continue;
mc[i]+mc[j];
}
}
}
if(mc[i]<one)
mc[i].setNum(1);
}
bignum tns,han,stn;
tns.setNum(0);
han.setNum(0);
for(int i=0;i<n;i++)
if(ans==dp[i]&&(next[i]==0||(next[i]&&f[next[i]]!=f[i])))
han+mc[i];
han.print();
}
void init_next()
{
memset(next,0,sizeof(next));
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
if(f[j]==f[i])
{
next[i]=j;
break;
}
}
}
int main()
{
init();
slove();
return 0;
}