Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ======================
- [ ___T_ ]
- [ | - + | ]
- [ |__v__|=> HI:-) ]
- [ .=[::+]=. ]
- [ ]=' [___] '=[ ]
- [ / | ]
- [ _\ |_ ]
- ======================
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- const int maxN = 212;
- int n,k,mod;
- lli grid[maxN][22][12];
- vector<int> nums(maxN + 1);
- lli solve(int i,int rem,int count){
- if(i > n or count == k){
- return (rem == 0 and count == k);
- }
- if(grid[i][rem][count] != -1){
- return grid[i][rem][count];
- }
- int x = (nums[i] + rem) % mod;
- if(x < 0 ){
- x += mod;
- }
- return grid[i][rem][count] = solve(i + 1,x,count + 1) + solve(i + 1,rem,count);
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int T = 1;
- int q;
- while(cin >> n >> q and n != 0 and q != 0){
- for(int i = 1;i <= n; i++){
- cin >> nums[i];
- }
- cout << "SET " << T++ << ":\n";
- for(int i = 1;i <= q; i++){
- cin >> mod >> k;
- memset(grid,-1,sizeof(grid));
- cout << "QUERY " << i << ": " << solve(1,0,0) << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement