A.水題,輸出圖形
B.水題
C.概率題
/* m, n 最大數為k的總數為 k^n - (k-1)^n 所以最大數為k的期望為 (k^n - (k-1)^n) / (m^n) */ #includeusing namespace std; int main() { int n, m; int i, j; scanf("%d%d", &m, &n); double ans = m; for(i=1; i<=m-1; ++i) { double x = i*1.0/m; ans = ans - pow(x, n); } printf("%.12f\n", ans); return 0; }
D. 狀態壓縮DP
#includeusing namespace std; int pri[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int dp[105][1<<16]; int p[105][1<<16]; int mask[60]; //mask[i]已二進制形式表示是否含有pri[j] int a[105]; int main() { int n, i, j, k; for(i=1; i<60; ++i) for(j=0; j<16; ++j) if(i%pri[j]==0) mask[i] |= 1< dp[i-1][j] + abs(a[i]-k)) { dp[i][j|mask[k]] = dp[i-1][j] + abs(a[i]-k); p[i][j|mask[k]] = k; } } } vector ans; for(int i=n, m=min_element(dp[i], dp[i]+(1<<16)) - dp[i]; i>0; m ^= mask[p[i][m]], --i) ans.push_back(p[i][m]); for(i=1; i<=n; ++i) printf("%d ", ans[n-i]); return 0; }