-
Yinyangshi is a famous RPG game on mobile phones.
Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Each time you can only draw one card, all the cards appear randomly with same probability 1/n. Kim can get 1 coin each day. Suppose Kim has 0 coin and no cards on day 0. Every W days, Kim can draw a card with W coins. In this problem ,we define W=(n-1)!.
Now Kim wants to know the expected days he can collect all the n kinds of cards.
Input
-
The first line an integer T(1 ≤ T ≤ 10). There are T test cases.
The next T lines, each line an integer n. (1≤n≤3000)
Output
- For each n, output the expected days to collect all the n kinds of cards, rounded to one decimal place.
Sample Input
-
4 1 2 5 9
Sample Output
-
1.0 3.0 274.0 1026576.0\
十几次失败之后终于过了,数要4位存一次,一开始用结构体一直tle。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; const int mx = 9200; const int mod = 1e4; int sum[mx], jie[mx], te[mx]; int po; void dis(){ printf("%d",sum[po]); for(int i = po - 1; i>=0; i--) printf("%04d", sum[i]); puts(".0"); } void mul( int x){ for(int i = 0; i <= po; i++){ jie[i] = jie[i] * x; } for(int i = 0; i <= po; i++){ if(jie[i] >= mod){ jie[i + 1] += jie[i] / mod; jie[i] = jie[i] % mod; } } if(jie[po + 1] > 0) po++; } void add(int x){ int cnt = 0; for(int i = po; i >= 0; i--){ cnt = cnt * mod + jie[i]; if(cnt < x){ te[i] = 0; continue; } te[i] = cnt / x; cnt = cnt % x; } for(int i = po; i >= 0; i--){ sum[i]+=te[i]; } for(int i = 0; i <= po; i++){ if(sum[i] >= mod){ sum[i + 1] += sum[i] / mod; sum[i] = sum[i] % mod; } } if(sum[po + 1] > 0) po++; } int main(){ int T, n, x; scanf("%d", &T); //T = 90; while(T--){ scanf("%d", &n); memset(sum, 0, sizeof(sum)); memset(jie, 0, sizeof(jie)); jie[0] = 1; po = 0; for(int i = 2; i <= n; i++){ mul(i); } for(int i = 1; i <= n; i++){ add(i); } dis(); } return 0; }
\\
本文已参与「新人创作礼」活动,一起开启掘金创作之路