A simple greedy problem.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 476 Accepted Submission(s): 193
Problem Description
Input
The first line of input contains only one integer T(<=70), the number of test cases. For each case, the first line contains 1 integer, N(<=1000), indicating the number of creeps. The next line contain N integers, representing the current health of each creep(<=1000).
Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. For each case, just output the maximum CS Dragon can get.
Sample Input
2 5 1 2 3 4 5 5 5 5 5 5 5
Sample Output
Case #1: 5 Case #2: 2
Author
BJTU
Source
#include#include #include 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 =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;}