SRM 599 D2L3: SimilarNames2,dp
来源:互联网 发布:ntp服务器windows工具 编辑:程序博客网 时间:2024/04/30 03:49
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12871&rd=15711
dp[i][j] 表示 当前已选择前 i 个字符串,且最后一个字符串为 names[j]。
代码:
#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)/*************** Program Begin **********************/const int MOD = 1000000007;int dp[55][55];class SimilarNames2 {public:int L, n;vector <string> names;bool isPrefix(string s, string mathch){if (s.size() < mathch.size()) {return false;} else {return ( mathch == s.substr(0, mathch.size()) );}}int rec(int cur, int s){if (cur == L) {return 1;}int & res = dp[cur][s];if (res != -1) {return res;}res = 0;for (int i = 0; i < n; i++) {if (i != s && isPrefix(names[i], names[s])) {res += rec(cur + 1, i);res %= MOD;}}return res;}int count(vector <string> names, int L) {this->L = L;this->names = names;this->n = names.size();memset(dp, -1, sizeof(dp));long long res = 0;for (int i = 0; i < n; i++) {res += rec(1, i);res %= MOD;}for (int i = 1; i <= n - L; i++) {res *= i;res %= MOD;}return res;}};/************** Program End ************************/
1 0
- 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 572 D2L3:DistinctRemainders,dp,math
- SRM 627 D2L3: BubbleSortWithReversals, dp, 冒泡排序
- SRM 594 D2L3:PolygonTraversal2,backtrack
- SRM 617 D2L3: MyVeryLongCake, Math
- SRM 621 D2L3: MixingColors, math
- SRM 510 D2L3:TheLuckyBasesDivTwo,brute force,optimization
- SRM 571 D2L3:MagicMoleculeEasy,brute force
- SRM 622 D2L3: Subsets, math, backtrack
- SRM 626 D2L3:NegativeGraphDiv2,构造新图
- 北风网--3G-安卓零基础就业班
- IT职业规划模型图
- Linux程序设计——用getopt处理命令行参数
- HDU1009
- ios tableview 那些事(二十) ios7 分割线短 15 像素(废弃) ios8方法
- SRM 599 D2L3: SimilarNames2,dp
- myeclipse中java文件头注释格式设置
- 2013年,满满的一年
- 基于 Jenkins 快速搭建持续集成环境
- Eclipse无法识别(手机)设备解决方案
- 惠普DL388 G7安装win Server 2003
- canvas像素级操作实现各种滤镜之高斯模糊
- C/C++回调函数简要介绍
- 数据库--SQLServer--如何找到包含某列最大值的那一行