hiho Week 8 register

Ended

Participants:541

Verdict:Accepted
Score:100 / 100
Submitted:2014-08-30 13:31:28

Lang:GCC

Edit
1
2
3
4
5
6
7
8
9
10
11
12
#define max(x,y) (x>y?x:y)
int N,M,Q,D[1024][1000],t,A,T,c,r,b,i,j;
main(){
    for(scanf("%d%d%d",&N,&M,&Q),t=(1<<(M-1))-1,scanf("%d",&A),D[1][0]=A,i=1;i<N&&scanf("%d",&A);++i)
        for(j=0;b=(j&t)<<1,j<(1<<M);T=(++j)&t,c=0){
            while(T)c+=(T&1),T>>=1;
            if(c<Q)D[b|1][i]=max(D[b|1][i],D[j][i-1]+A);
            D[b][i]=max(D[b][i],D[j][i-1]);
            r=max(r,max(D[b][i],D[b|1][i]));
        }
    printf("%d\n",r);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX