Skip to content

Instantly share code, notes, and snippets.

@jskyzero
Created March 21, 2019 08:01
Show Gist options
  • Save jskyzero/95be52be97b0e97983a2b824387c9847 to your computer and use it in GitHub Desktop.
Save jskyzero/95be52be97b0e97983a2b824387c9847 to your computer and use it in GitHub Desktop.
Mi_Question
#include<iostream>
// slot choice result
// 1 3 3
// 2 3 1 3
// 2 2
// 3 1
int f(int slot, int choice) {
int result = 0;
if (slot == 1) return choice;
for (int i = 0; i < choice; i++) {
result += f(slot - 1, choice - i);
}
return result;
}
int main() {
std::cout << "slot\tchoice\t" << std::endl;
std::cout << "1\t1\t" << f(1, 1) << std::endl;
std::cout << "1\t2\t" << f(1, 2) << std::endl;
std::cout << "1\t3\t" << f(1, 3) << std::endl;
std::cout << "2\t3\t" << f(2, 3) << std::endl;
std::cout << "3\t3\t" << f(3, 3) << std::endl;
std::cout << "4\t4\t" << f(4, 4) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment