SRM 572 D2L3:DistinctRemainders,dp,math
来源:互联网 发布:游乐园网络推广文案 编辑:程序博客网 时间:2024/06/10 06:10
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12384&rd=15492
参考:http://apps.topcoder.com/wiki/display/tc/SRM+572
把数学部分搞定之后dp比较简单,关键是找到所取数的模集与最终序列种数的关系。
代码:
#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <iostream>#include <sstream>#include <iomanip>#include <bitset>#include <string>#include <vector>#include <stack>#include <deque>#include <queue>#include <set>#include <map>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <cstring>#include <ctime>#include <climits>using namespace std;#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)typedef pair<int, int> pii;typedef long long llong;typedef pair<llong, llong> pll;#define mkp make_pair/*************** Program Begin **********************/const int MOD = 1e9 + 7;long long dp[51][51][2501];class DistinctRemainders {public:long long N;int M;int rec(int cur, int K, int q){long long & res = dp[cur][K][q];if (res != -1) {return res;}if (M == cur) {// base casesif (q % M == N % M) {long long Q = (N - q) / M;res = K;// C(Q + K - 1, K - 1) * K!for (int i = 0; i < K - 1; i++) {res *= ( (Q + K - 1 - i) % MOD );res %= MOD;}return res;} else {res = 0;return res;}}res = 0;// addres += rec(cur + 1, K + 1, q + cur);res %= MOD;// ignoreres += rec(cur + 1, K, q);res %= MOD;return (int)res;}int howMany(long long N, int M) {int res = 0;this->N = N;this->M = M;memset(dp, -1, sizeof(dp));res = rec(0, 0, 0);return res;}};/************** Program End ************************/
0 0
- SRM 572 D2L3:DistinctRemainders,dp,math
- SRM 617 D2L3: MyVeryLongCake, Math
- SRM 621 D2L3: MixingColors, math
- SRM 599 D2L3: SimilarNames2,dp
- SRM 609 D2L3: VocaloidsAndSongs,dp
- SRM 602 D2L3:BlackBoxDiv2,dp
- SRM 604 D2L3:FoxConnection2,dp
- SRM 591 D2L3:YetAnotherTwoTeamsProblem,dp
- SRM 610 D2L3:MiningGoldEasy,dp
- SRM 612 D2L3:PowersOfTwo,dp
- SRM 615 D2L3:MergeStrings,dp
- SRM 620 D2L3: RandomGraph, dp
- SRM 622 D2L3: Subsets, math, backtrack
- SRM 627 D2L3: BubbleSortWithReversals, dp, 冒泡排序
- SRM 594 D2L3:PolygonTraversal2,backtrack
- SRM 628 D1L3:DoraemonPuzzleGame,math,期望,dp
- SRM 510 D2L3:TheLuckyBasesDivTwo,brute force,optimization
- SRM 571 D2L3:MagicMoleculeEasy,brute force
- 平均距离
- 如何写出高性能的SQL语句
- bibtex文献引用之ctex
- 大数据里看两会
- 锁定表头行头
- SRM 572 D2L3:DistinctRemainders,dp,math
- Kettle 与 Talend Open Studio 的 ETL 比较以及其它ETL工具(网络收集)
- ios NSDate 时间戳 时间间隔
- 2--1学生成绩统计
- Hive体系结构<转>
- 我不知道啊
- Hibernate 关系映射 总结整理
- Ubuntu12.10 编译Android 4.2
- HtmlAgilityPack.dll网页抓取数据