本题从概率出发计算期望,用不到dp,因为白球和黑球完全公平,取1次即期望+0.5:
#include <cmath> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <set> #include <stack> #include <stdio.h> using namespace std; typedef long long ll; const ll mod = 1e9; const int maxn = 1e7; int main(){ int n; cin >> n; cout << 1+n/2; if(n&1) cout << ".5000000"; else cout << ".0000000"; }