Codecraft-17 and Codeforces Round #391 C. Felicity is Coming!
2018-02-02 23:11
393 查看
题目来源:http://codeforces.com/contest/757/problem/C
统计每种Pokemon出现的组的编号,存在一个vector。注意进行排序以及阶乘的处理。
另外,取余运算用减法效率要高于%运算。
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxm=1e6+10;
const int mod=1e9+7;
vector<int> v[maxm];
long long f[maxm];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
for(int j=1;j<=x;j++)
{
int c;cin>>c;
v[c].push_back(i);
}
}
f[0]=f[1]=1;
for(int i=2;i<=m;i++)
{
f[i]=f[i-1]*i;
if(f[i]>mod)f[i]-=f[i]/mod*mod;
}
for(int i=1;i<=m;i++)sort(v[i].begin(),v[i].end());
sort(v+1,v+1+m);
long long ans=1;
int cnt=1;
for(int i=2;i<=m;i++)
{
if(v[i]==v[i-1])cnt++;
else
{
ans*=f[cnt];
if(ans>mod)ans-=ans/mod*mod;
cnt=1;
}
}
ans*=f[cnt];
if(ans>mod)ans-=ans/mod*mod;
cout<<ans<<endl;
return 0;
}
统计每种Pokemon出现的组的编号,存在一个vector。注意进行排序以及阶乘的处理。
另外,取余运算用减法效率要高于%运算。
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxm=1e6+10;
const int mod=1e9+7;
vector<int> v[maxm];
long long f[maxm];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
for(int j=1;j<=x;j++)
{
int c;cin>>c;
v[c].push_back(i);
}
}
f[0]=f[1]=1;
for(int i=2;i<=m;i++)
{
f[i]=f[i-1]*i;
if(f[i]>mod)f[i]-=f[i]/mod*mod;
}
for(int i=1;i<=m;i++)sort(v[i].begin(),v[i].end());
sort(v+1,v+1+m);
long long ans=1;
int cnt=1;
for(int i=2;i<=m;i++)
{
if(v[i]==v[i-1])cnt++;
else
{
ans*=f[cnt];
if(ans>mod)ans-=ans/mod*mod;
cnt=1;
}
}
ans*=f[cnt];
if(ans>mod)ans-=ans/mod*mod;
cout<<ans<<endl;
return 0;
}
相关文章推荐
- Codecraft-18 and Codeforces Round#458 C. Travelling Salesman and Special Numbers(数位DP)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- C. Felicity is Coming! (STL水过)
- 【前缀和 && 思维转换】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)Molly's Chemicals
- Codeforces Round #291 (Div. 2)C.Watto and Mechanism——字典树+dfs
- Codeforces Round #425 (Div. 2) B. Petya and Exam【模拟】
- COdeforces Round #264 (Div. 2) C. Gargari and Bishops
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #291 (Div. 2)-D. R2D2 and Droid Army(RMQ)
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
- 【Codeforces Round 374 (Div 2)D】【贪心】 Maxim and Array n个数做K次±X使得乘积尽可能小
- E. Vladik and cards Codeforces Round #384 (Div. 2) 好题 二分+(贪心+状态压缩DP)判断
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
- Mike and gcd problem Codeforces Round #410 (Div. 2)
- Codeforces Round #179 (Div. 2) C Greg and Array
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- 【Codeforces Round 354 (Div 2)A】【水题 贪心】Nicholas and Permutation 恰好交换一次的pos[n]-pos[1]