CodeForce---Educational Codeforces Round 3 The best Gift 解题报告

对于这题笔者认为可以用数学排列来算,但是由于笔者很懒所以抄了一段大神的代码来交个大家了,

这位大神的基本想法就是通过记录各类书的数量,再暴力破解;

下面贴出这位大神的代码吧:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 int h[15];
 7 int main()
 8 {
 9     int n,m;
10     scanf("%d%d",&n,&m);
11     for(int i=1;i<=n;i++)
12     {
13         int x;scanf("%d",&x);
14         h[x]++;
15     }
16     long long ans = 0;
17     for(int i=1;i<=m;i++)
18         for(int j=i+1;j<=m;j++)
19             ans+=h[i]*h[j];
20     cout<<ans<<endl;
21 }
原文地址:https://www.cnblogs.com/Bincoder/p/5064820.html