1. 神奇的青蛙
#include <iostream> #include <vector> using namespace std; long solve(long n) { vector<long> dp(n + 1, 0); dp[0] = 1; dp[1] = 1; for(long i = 2; i < n + 1; ++i) { for(long j = 1; j <= i; j <<= 1) { dp[i] += dp[i-j]; } } return dp[n]; } int main() { long N; cin >> N; cout << solve(N-1); return 0; }2. 找倍数
#include <iostream> #include <vector> using namespace std; bool solve(vector<int> nums, int m, int k) { if(k % 2 != 1) k /= 2; int count = 0; for(int i = 0; i < nums.size(); ++i) { if(nums[i] % k == 0) count++; } return count >= m; } int main() { int T; cin >> T; while(T--) { int m, n, k; cin >> n >> m >> k; vector<int> nums(n); for(int i = 0; i < n; ++i) { cin >> nums[i]; } cout << (solve(nums, m, k) ? "Yes" : "No"); } return 0; }
全部评论
(4) 回帖