标签:str max style for else ret lan names cst
易错点:
#include<cstdio> #include<iostream> using namespace std; const int MAXN=1e4; int a[MAXN]; int f[MAXN],num[MAXN]; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } f[1]=1; int ans1=1; for(int i=1;i<=n;i++){ f[i]=1; for(int j=1;j<i;j++){ if(a[j]>a[i]){ f[i]=max(f[i],f[j]+1); ans1=max(ans1,f[i]); } } } for(int i=1;i<=n;i++){ if(f[i]==1)num[i]=1; for(int j=1;j<i;j++){ if(a[j]>a[i]&&f[i]==f[j]+1)num[i]+=num[j]; else if(a[i]==a[j]&&f[i]==f[j])num[i]=0; } } int ans2=0; for(int i=1;i<=n;i++){ if(f[i]==ans1)ans2+=num[i]; } printf("%d %d\n",ans1,ans2); return 0; }
标签:str max style for else ret lan names cst
原文地址:https://www.cnblogs.com/zbsy-wwx/p/11625729.html