SRM 599 DIV2 950
来源:互联网 发布:单片机哪种好 编辑:程序博客网 时间:2024/04/20 09:47
太弱了。。。。这么简单的题也只能比赛之后写。。。。。
roblem Statement
Fox Ciel has a list of names on her computer. In this problem, a name is simply a non-empty string of lowercase letters. All names in her list are distinct.One day, when she left her seat, she forgot to lock her computer. Then, Lun the mischievous dog appeared, and randomly shuffled the order of the names in her list.
Now, Ciel has to restore the original order of names using her memory. You are given a vector <string> names and an int L. namescontains all names in the shuffled list in the order they appear. L describes Ciel's memory of the original list. She remembers that, for each i between 0 and L-2, inclusive, the i-th (0-indexed) name in the original list was a prefix of the (i+1)-th name.
Let X be the number of possible orders of the names in the original list that are consistent with Ciel's memory. Calculate and return the value (X modulo 1,000,000,007). X can be 0, which means Ciel's memory is inconsistent with the names in the list.
Definition
Class:SimilarNames2Method:countParameters:vector <string>, intReturns:intMethod signature:int count(vector <string> names, int L)(be sure your method is public)Notes
-A prefix of a string is the result of erasing zero or more characters from the right end of that string.Constraints
-names will contain between 2 and 50 elements, inclusive.-Each element of names will contain between 1 and 50 characters, inclusive.-Each character of each element of names will be a lowercase letter ('a'-'z').-Elements of names will be distinct.-L will be between 1 and n, inclusive, where n is the number of elements in names.Examples
0) {"kenta", "kentaro", "ken"}2Returns: 3Here, Ciel's list contains 3 names. She remembers that the 0-th name was a prefix of the 1-st name in the original list. Here are the all possible orders of names in the original list:- ken, kenta, kentaro
- ken, kentaro, kenta
- kenta, kentaro, ken
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <deque>#include <cstring>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;const int MOD=1000000007;int qianzui[100];int Com[60][60];void getCom(){ Com[0][0]=1; for(int i=1;i<=50;i++) Com[i][i]=Com[0][i]=1; for(int i=2;i<=50;i++) { for(int j=1;j<i;j++) { Com[j][i]=(Com[j-1][i-1]+Com[j][i-1])%MOD; } }}int getC(int l,int z){ if(l>z) return 0; if(l==0||l==z) return 1; return Com[l][z];}class SimilarNames2 {public:int count(vector <string> names, int L){ getCom(); int n=names.size(); memset(qianzui,0,sizeof(qianzui)); sort(names.begin(),names.end()); ///预处理前缀 for(int i=1;i<n;i++) { int len2; for(int j=0;j<i;j++) { len2=names[j].size(); if(names[i].substr(0,len2)==names[j]) { qianzui[i]=max(qianzui[j]+1,qianzui[i]); } } } long long int ans=0; for(int i=0;i<n;i++) { ans=(ans+getC(L-1,qianzui[i]))%MOD; } for(int i=2;i<=n-L;i++) { ans=(ans*i)%MOD; } return ans%MOD;}};///<%:testing-code%>//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!// BEGIN KAWIGIEDIT TESTING
- SRM 599 DIV2 950
- SRM 542 DIV2 950 StrangeDictionary
- SRM 599 div2 250 500
- SRM 531 div1 600/300 div2 950
- TC-SRM-609-DIV2-950- VocaloidsAndSongs
- SRM 551 div2 950(DP, 环形+优化)
- SRM 114 DIV2 [550]
- SRM 398 DIV2 [250]
- SRM 399 DIV2 [250]
- SRM 387 DIV2 [250]
- SRM 387 DIV2 [600]
- SRM 397 DIV2 [500]
- SRM 400 DIV2 [250]
- SRM 400 DIV2 [500]
- SRM 397 DIV2 [1000]
- SRM 405 DIV2
- SRM 421Div2 500
- SRM 457 Div2 500
- 12月3号面试题记录
- fecn-create和fecn-adapt的作用
- 基于visual Studio2013解决C语言竞赛题之0904文件排序
- wikioi 1042 进制转换
- TCP Keepalive 笔记
- SRM 599 DIV2 950
- Problem 56: 某种序列(大数加法+数列)
- Windows下Emacs+ Distel的配置
- pache 合理配置KeepAlive选项对服务器性能的影响
- openresty php luajit
- struts整合spring插件出现如下异常:Unable to load jar:struts2-spring-plugin-2.3.15.3.jar!/struts-plugin.xml
- 开发者的义不容辞
- 我们是幸福的
- hdu 1754 I Hate It (线段树)