本文主要是介绍LightOJ 1038 - Race to 1 Again(dp),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:LightOJ 1038 - Race to 1 Again
代码
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>using namespace std;
const int maxn = 1e5;double dp[maxn + 5];
vector<int> G[maxn + 5];void init () {for (int i = 2; i <= maxn; i++)for (int j = i; j <= maxn; j += i)G[j].push_back(i);dp[1] = 0;for (int i = 2; i <= maxn; i++) {double s = 0;for (int j = 0; j < G[i].size(); j++)s += dp[i / G[i][j]];dp[i] = (G[i].size() + 1 + s) / G[i].size();}
}int main () {init();int cas, n;scanf("%d", &cas);for (int kcas = 1; kcas <= cas; kcas++) {scanf("%d", &n);printf("Case %d: %.6lf\n", kcas, dp[n]);}return 0;
}
这篇关于LightOJ 1038 - Race to 1 Again(dp)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!