不知道我的方法对不对
#include<iostream> #include<vector>
#include<queue> #include<map> #include<algorithm> typedef unsigned long long ll; using namespace std; int main() { int X; cin >> X; int L, T, N; cin >> L >> T >> N; vector<int> nums(N, 0); map<int, int> Map; for (int i = 0; i < N; i++) { cin >> nums[i]; Map[nums[i]]++; } sort(nums.begin(), nums.end()); int count = 0; vector<int> dp(X + 1, 100000); dp[0] = 0; for (int i = nums[0]; i <= X; i++) { count = 0; for (int j = L; j <= T; j++) { if (i - j >= 0&&dp[i-j]!=100000) { count++; if (count == 1) { if (Map[i] > 0) { dp[i] = dp[i - j] + 1; } else { dp[i] = dp[i - j]; } continue; } if (Map[i] > 0) { dp[i] = min(dp[i], dp[i - j] + 1); } else { dp[i] = min(dp[i], dp[i - j]); } } } cout << dp[i] << endl; } return 0; }