SRM 599 DIV2 950

本文介绍了一种算法,用于解决名字列表被随机打乱后,依据部分记忆重构原始顺序的问题。通过分析名字间的前缀关系,该算法能高效计算出可能的原始顺序数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


太弱了。。。。这么简单的题也只能比赛之后写。。。。。

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 Lnamescontains 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:SimilarNames2
Method:count
Parameters:vector <string>, int
Returns:int
Method 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"}
2
Returns: 3
Here, 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
Note that it is possible that the order of the names in the original list coincides with that of the shuffled list.
1) 
 
{"hideo", "hideto", "hideki", "hide"}
2
Returns: 6
Again, she remembers that the 0-th name was a prefix of the 1-st name in the original list. The only thing we can be sure is that the 0-th name was "hide".
2) 
 
{"aya", "saku", "emi", "ayane", "sakura", "emika", "sakurako"}
3
Returns: 24
This time, she remembers not only the fact that the 0-th name was a prefix of the 1-st name, but also the fact that the 1-st name was a prefix of the 2-nd name. The first 3 names should be "saku", "sakura", "sakurako" in this order.
3) 
 
{"taro", "jiro", "hanako"}
2
Returns: 0
No name is a prefix of another name in this case, so her memory is inconsistent.
4) 
 
{"alice", "bob", "charlie"}
1
Returns: 6
L = 1 means that she actually remembers nothing.
5) 
 
{"ryota", "ryohei", "ryotaro", "ryo", "ryoga", "ryoma", "ryoko", "ryosuke", "ciel", "lun", "ryuta", "ryuji", "ryuma", "ryujiro", "ryusuke", "ryutaro", "ryu", "ryuhei", "ryuichi", "evima"}
3
Returns: 276818566

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




### 关于 SACMA SRM01 的中文版资料 SACMA SRM01 是由复合材料学会(Society for the Advancement of Material and Process Engineering, SAMPE)发布的标准之一,主要用于描述短切玻璃纤维增强热固性模塑料的性能测试方法[^1]。该标准通常涉及材料特性、制备工艺以及质量控制等方面的内容。 对于寻找 SACMA SRM01 中文版文档的需求,可以通过以下途径获取: #### 1. 官方渠道 SAMPE 或其中国分会可能提供官方翻译版本的下载服务。建议访问 SAMPE China 的官方网站或其他授权机构网站查询是否有正式的中文译本[^2]。 #### 2. 图书馆资源 部分高校图书馆或行业技术中心会收藏此类国际标准的技术文件及其翻译件。可以联系所在地区的科技图书馆或者通过 Interlibrary Loan (ILL) 请求借阅相关文献[^3]。 #### 3. 商业平台购买 一些商业数据库如 CNKI(知网)、万方数据等可能会收录经过合法授权的标准翻译版本。如果这些平台上未找到具体条目,则需进一步确认是否已发布官方认可的中文版本[^4]。 以下是基于 Python 编写的简单脚本来演示如何自动化搜索某些在线学术资源库中的关键词匹配项: ```python import requests from bs4 import BeautifulSoup def search_sacma(keyword="SACMA SRM01"): url = f"https://example-academic-resource.com/search?q={keyword}" response = requests.get(url) soup = BeautifulSoup(response.text, &#39;html.parser&#39;) results = [] for item in soup.find_all(&#39;div&#39;, class_=&#39;result-item&#39;): title = item.find(&#39;h3&#39;).text.strip() link = item.find(&#39;a&#39;)[&#39;href&#39;] abstract = item.find(&#39;p&#39;, class_=&#39;abstract&#39;).text.strip()[:150]+&#39;...&#39; results.append({ "title": title, "link": link, "abstract": abstract }) return results if __name__ == "__main__": res = search_sacma("SACMA SRM01") for r in res: print(f"{r[&#39;title&#39;]}\n{r[&#39;link&#39;]}\nAbstract: {r[&#39;abstract&#39;]}\n---\n") ``` 请注意以上代码仅为示例用途,在实际应用前应调整目标网址并遵循各站点的服务条款与版权政策[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值