编程介的小学生 2019-08-26 21:47 采纳率: 0.4%
浏览 79

正确使用C语言解决Sleeping

Problem Description
ZZZ is an enthusiastic ACMer and he spends lots of time on training. He always stays up late for training. He needs enough time to sleep, and hates skipping classes. So he always sleeps in the class. With the final exams coming, he has to spare some time to listen to the teacher. Today, he hears that the teacher will have a revision class. The class is N (1 <= N <= 1000) minutes long. If ZZZ listens to the teacher in the i-th minute, he can get Ai points (1<=Ai<=1000). If he starts listening, he will listen to the teacher at least L (1 <= L <= N) minutes consecutively. Its the most important that he must have at least M (1 <= M <= N) minutes for sleeping (the M minutes neednt be consecutive). Suppose ZZZ knows the points he can get in every minute. Now help ZZZ to compute the maximal points he can get.

Input
The input contains several cases. The first line of each case contains three integers N, M, L mentioned in the description. The second line follows N integers separated by spaces. The i-th integer Ai means there are Ai points in the i-th minute.

Output
For each test case, output an integer, indicating the maximal points ZZZ can get.

Sample Input
10 3 3
1 2 3 4 5 6 7 8 9 10

Sample Output
49

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-31 13:11
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    #include <stdio.h>
    int main(){
    	int n,m,l;
    	scanf("%d %d %d",&n,&m,&l);
    	int arr[n+1];
    	for(int i=0;i<n;i++){
    		scanf("%d",arr+i);
    	}
    	int dp[m][1001],dp2[m][1001];
    	dp[0][arr[0]]=arr[0];
    	for(int i=1;i<m;i++){
    		dp[i][arr[i]]=arr[i]+dp[i-1][arr[i]];
    	}
    	for(int i=m;i<m+n;i++){
    		dp2[i][arr[i-m]]=(arr[i]-arr[i-m])+(dp2[i-1][arr[i-m]]);
    		for(int j=i+1;j<i+m;j++){
    			dp2[i][arr[j]]+=min(dp2[i-1][arr[j]],dp2[i-1][arr[j-m]]);
    		}
    	}
    	printf("%d\n",max(dp[m][arr[m]],dp2[m][arr[m]]));
    	return 0;
    }
    
    评论

报告相同问题?