#include <iostream> #include <vector> #include <stdio.h> using namespace std; void dfs(vector<int>& box, int index, long long& count, long long& sum) { if(index == 10) { sum++; if(box[0]*box[1]*box[2]*box[3]*box[4] != 0) count++; return; } for(int i = 0; i < 5; i++) { box[i]++; dfs(box, index + 1, count, sum); box[i]--; } } int main() { vector<int> box(5, 0); long long count = 0; long long sum = 0; dfs(box, 0, count, sum); printf("出现五个颜色的情况:%lld
", count); printf("所有的情况: %lld
", sum); printf("出现五色的概率为: %f
", (double)count/sum); return 0; }