#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
struct hashuj {
size_t operator()(const vector<ll>& vec) const {
size_t h = 0;
for (ll x : vec) {
h = h * 31 + x;
}
return h;
}
};
unordered_map <vector <ll>, ll,hashuj> memo;
ll n,k,m,kOdw;
ll MOD = 1000000007;
ll modPow (ll base, ll x, ll mod) {
ll wyn = 1;
base = base%mod;
while (x > 0) {
if (x%2 == 1) wyn = (wyn*base)%mod;
base = (base*base)%mod;
x/=2;
}
return wyn;
}
ll brute (vector <ll> punkty) {
sort(punkty.begin(),punkty.end());
auto it = memo.find(punkty);
if (it != memo.end()) return it->second;
if (punkty.back() >= m) return 0;
ll tym = 0;
vector <ll> newPunkty = punkty;
for (int i = 1; i <= k; i++) {
newPunkty[0]++;
tym+=brute(newPunkty);
tym%=MOD;
}
tym%=MOD;
ll wyn = (1+tym*kOdw)%MOD;
memo[punkty] = wyn;
return wyn;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> m;
vector <ll> punkty(n);
kOdw = modPow(k,MOD-2,MOD);
cout << brute(punkty)%MOD << "\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <iostream> #include <vector> #include <algorithm> #include <unordered_map> using namespace std; typedef long long ll; struct hashuj { size_t operator()(const vector<ll>& vec) const { size_t h = 0; for (ll x : vec) { h = h * 31 + x; } return h; } }; unordered_map <vector <ll>, ll,hashuj> memo; ll n,k,m,kOdw; ll MOD = 1000000007; ll modPow (ll base, ll x, ll mod) { ll wyn = 1; base = base%mod; while (x > 0) { if (x%2 == 1) wyn = (wyn*base)%mod; base = (base*base)%mod; x/=2; } return wyn; } ll brute (vector <ll> punkty) { sort(punkty.begin(),punkty.end()); auto it = memo.find(punkty); if (it != memo.end()) return it->second; if (punkty.back() >= m) return 0; ll tym = 0; vector <ll> newPunkty = punkty; for (int i = 1; i <= k; i++) { newPunkty[0]++; tym+=brute(newPunkty); tym%=MOD; } tym%=MOD; ll wyn = (1+tym*kOdw)%MOD; memo[punkty] = wyn; return wyn; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> m; vector <ll> punkty(n); kOdw = modPow(k,MOD-2,MOD); cout << brute(punkty)%MOD << "\n"; return 0; } |
English