B. The Best Gift

题目连接:

http://www.codeforces.com/contest/609/problem/B

Description

Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.

In the bookshop, Jack decides to buy two books of different genres.

Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.

The books are given by indices of their genres. The genres are numbered from 1 to m.

Input

The first line contains two positive integers n and m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres.

The second line contains a sequence a1, a2, ..., an, where ai (1 ≤ ai ≤ m) equals the genre of the i-th book.

It is guaranteed that for each genre there is at least one book of that genre.

Output

Print the only integer — the number of ways in which Jack can choose books.

It is guaranteed that the answer doesn't exceed the value 2·109.

Sample Input

4 3

2 1 3 1

Sample Output

5

Hint

题意

一共有n本书,每本书都属于m类中的一个,然后有一个人想拿两本书走,这两本书必须来自不同类别,问你一共有多少种拿法。

题解:

注意,m的数据范围只有10。所以我们只要记录每一类书有多少本就好了,然后种类就直接暴力算就好了。

代码

#include<bits/stdc++.h>
using namespace std; int h[15];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
int x;scanf("%d",&x);
h[x]++;
}
long long ans = 0;
for(int i=1;i<=m;i++)
for(int j=i+1;j<=m;j++)
ans+=h[i]*h[j];
cout<<ans<<endl;
}

Codeforces Educational Codeforces Round 3 B. The Best Gift 水题的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  4. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  6. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  7. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  8. Codeforces Beta Round #14 (Div. 2) A. Letter 水题

    A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...

  9. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

随机推荐

  1. 实测 windows下nginx很不稳定,换成squid好多了

    在windows server 2003 下尝试了号称支持50,000个并发连接数响应的nginx,结果相当不理想. 具体表现为时不时网页就卡住不动了,需要再刷新一次网页才能显示,而服务器cpu和内存 ...

  2. 已经被cocos2dx给折腾的想要放弃它,专注Unity3D的怀抱了!

    一直使用cocos2dx编写自己的2D小游戏,不得不说,编写个人的超级小规模的游戏,使用cocos2dx有一定的优势,首先门槛很低,编写2D游戏用起来也算顺手,可惜一直没有一个优秀的UI编辑器,好不容 ...

  3. NewtonPrincipia --- 公理或运动的定律 --- 系理二

    NewtonPrincipia --- 公理或运动的定律 --- 系理二 自然哲学的数学原理>公理或运动的定律>系理II 平行四边形ABCD,那么:直接的力AD由任意的力AB和BD合成,直 ...

  4. failback 和failover

    dubbo 和motan都有在注册中心中都有这个概念 Failover 失效转移通俗地说,即当A无法为客户服务时,系统能够自动地切换,使B能够及时地顶上继续为客户提供服务,且客户感觉不到这个为他提供服 ...

  5. fopen警告处理方式

    warning C4996: “fopen”被声明为否决的 问题:vs2005中编程时,遇到如下: warning C4996: “fopen”被声明为否决的. 解释:微软的警告,主要是那些都是C库的 ...

  6. 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码

    JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...

  7. 第二百零八天 how can I 坚持

    今天徐斌生日,生日快乐.买了两个小蛋糕,哈哈 还买了两条熊猫鱼.不知道鱼会不会冻死啊,买了加热器又不想用,看他们造化吧. LOL不错的游戏的. 睡觉,好冷.

  8. 转】MyEclipse使用总结——MyEclipse去除网上复制下来的来代码带有的行号

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/3544208.html 感谢! 一.正则表达式去除代码行号 作为开发人员,我们经常从网上复制一些代码,有些时候复制 ...

  9. JSF 2 panelGrid example

    In JSF , "h:panelGrid" tag is used to generate HTML table tags to place JSF components in ...

  10. centos安装postfixadmin

    postfixadmin的安装,跟普通网站安装没什么区别 配置好虚拟目录,然后在数据库中创建数据库postfix 修改config.inc.php文件,详细搜索谷歌 访问http://www.你的域名 ...