#include <iostream> #include <vector> #define MOD_VAL 1000000007 //#define DEBUG uint64_t solve(int drzewa_left, int gatunki_left, int gatunki, std::vector<int> &day_len, int drzewa){ uint64_t output; #ifdef DEBUG //std::cout << "solve " << drzewa_left << " " << gatunki_left << "\n"; #endif if(drzewa_left == 0){ //Podzielone output=1; for(int i=0; i<day_len.size(); i++){ #ifdef DEBUG std::cout << day_len[i] << " "; #endif output=(output*(gatunki-i))%MOD_VAL; for(uint64_t j=0; j<(day_len[i]-2); j++){ output=(output*gatunki)%MOD_VAL; } } #ifdef DEBUG std::cout << "\n"; std::cout << "output1: " << output << "\n"; #endif //for(int i=1; i<=(drzewa-day_len.size()*2); i++){ // output=(output*gatunki)%MOD_VAL; //} //std::cout << "\n"; #ifdef DEBUG std::cout << "adding: " << output << "\n"; #endif return output; } if(gatunki_left == 0) return 0; output=0; for(int i=2; i<=drzewa_left; i++){ day_len.push_back(i); output = (output+solve(drzewa_left-i, gatunki_left-1, gatunki, day_len, drzewa))%MOD_VAL; day_len.pop_back(); } return output; } //int output; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n,m; std::cin >> n >> m; //output=0; std::vector<int> day_len; uint64_t out = solve(n,m, m, day_len, n); //std::cout << "output:\n"; std::cout << out << "\n"; }
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 | #include <iostream> #include <vector> #define MOD_VAL 1000000007 //#define DEBUG uint64_t solve(int drzewa_left, int gatunki_left, int gatunki, std::vector<int> &day_len, int drzewa){ uint64_t output; #ifdef DEBUG //std::cout << "solve " << drzewa_left << " " << gatunki_left << "\n"; #endif if(drzewa_left == 0){ //Podzielone output=1; for(int i=0; i<day_len.size(); i++){ #ifdef DEBUG std::cout << day_len[i] << " "; #endif output=(output*(gatunki-i))%MOD_VAL; for(uint64_t j=0; j<(day_len[i]-2); j++){ output=(output*gatunki)%MOD_VAL; } } #ifdef DEBUG std::cout << "\n"; std::cout << "output1: " << output << "\n"; #endif //for(int i=1; i<=(drzewa-day_len.size()*2); i++){ // output=(output*gatunki)%MOD_VAL; //} //std::cout << "\n"; #ifdef DEBUG std::cout << "adding: " << output << "\n"; #endif return output; } if(gatunki_left == 0) return 0; output=0; for(int i=2; i<=drzewa_left; i++){ day_len.push_back(i); output = (output+solve(drzewa_left-i, gatunki_left-1, gatunki, day_len, drzewa))%MOD_VAL; day_len.pop_back(); } return output; } //int output; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n,m; std::cin >> n >> m; //output=0; std::vector<int> day_len; uint64_t out = solve(n,m, m, day_len, n); //std::cout << "output:\n"; std::cout << out << "\n"; } |