1번)
5 3
1 3 2 3 22번)
8 5
1 5 4 3 2 4 5 2
1번)
82번)
25
1번
(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (4, 5)
from itertools import combinations
n, m = map(int, input().split())
kg = [0] * n
kg = list(map(int, input().split()))
cnt = 0
ball = list(combinations(kg, 2))
for i in combinations(kg, 2):
if i[0] != i[1]:
cnt += 1
print(i)
print(cnt)
n, m = map(int, input().split())
ball = [0] * n
ball = list(map(int, input().split()))
cnt = 0
for i in range(n):
for j in range(i + 1, n):
if ball[i] != ball[j]:
cnt += 1
print(ball[i], ball[j])
print(cnt)
n, m = map(int, input().split())
ball = list(map(int, input().split()))
kg = [0] * 11
result = 0
for x in ball:
kg[x] += 1
for i in range(1, m + 1):
n -= kg[i]
result += kg[i] * n
print(result)
문제를 보자마자 맨 처음 생각났던 아이디어가 itertools의 조합을 이용하여 계산한 후, 조건을 걸어주어 원하는 것을 출력하는 것이었다. 다른 방법으로도 풀어보고자 2중 for문을 사용하여 조합을 계산하게 되었다. 그러나 책에서 제공하는 코드는.. 이해가 잘 되지 않는다...