标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4842
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int stone[101], L, S, T, M, dp[2100], mpt[2100]; 7 int main(){ 8 int i, j, l, k, ptr = 0, minn; 9 cin >> L >> S >> T >> M; 10 for (i = 1; i <= M; i++) 11 scanf("%d", &stone[i]); 12 memset(mpt, 0, sizeof(mpt)); 13 memset(dp, 0, sizeof(dp)); 14 sort(stone + 1, stone + 1 + M); 15 stone[0] = ptr = 0; 16 for (i = 1; i <= M; i++){ 17 l = stone[i] - stone[i - 1]; 18 if (!(l % T)) k = T; 19 else k = l % T; 20 k = k + T; 21 k = min(k, l); 22 ptr = ptr + k; 23 mpt[ptr] = 1; 24 } 25 for (i = 1; i <= ptr + T; i++){ 26 minn = 0x7ffffff; 27 for (j = i - T; j <= i - S; j++) 28 if (j >= 0 && dp[j] < minn) 29 minn = dp[j]; 30 dp[i] = minn + mpt[i]; 31 } 32 minn = 0x7ffffff; 33 for (i = ptr + 1; i <= ptr + T; i++) 34 minn = min(minn, dp[i]); 35 printf("%d\n", minn); 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/zYx-ac/p/4572455.html