标签:for img tle pre number 技术 drag mode script
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 476 Accepted Submission(s): 193
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1005; int T,n,cas,a[N],b[N]; int f[N][N]; int main(){ for(scanf("%d",&T);T--;){ scanf("%d",&n);memset(b,-1,sizeof b); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for(int i=1;i<=n;i++){ for(int j=a[i];j;j--){ if(b[j]==-1){ b[j]=a[i];break; } } } memset(f,-1,sizeof f); f[0][0]=0; for(int i=0,t;i<a[n];i++){ for(int j=0;j<=i+1;j++){ f[i+1][j+1]=f[i][j]; if((~b[i+1])&&(t=j-b[i+1]+i+1)>=0)f[i+1][t]=max(f[i+1][t],f[i][j]+1); } } int ans=0; for(int i=0;i<=a[n];i++){ ans=max(ans,f[a[n]][i]); } printf("Case #%d: %d\n",++cas,ans); } return 0; }
hdu4976 A simple greedy problem.
标签:for img tle pre number 技术 drag mode script
原文地址:http://www.cnblogs.com/shenben/p/6720280.html