목록문제 (388)
sm 기술 블로그
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] tmpNM = br.readLine().split(" "); int N = Integer.parseInt(tmpNM[0]); int M = Integer.parseInt(tmpNM[1]); int[][] A = new int[N][M]; for (int i = 0; i < N; i++) { String[] tmpA = br.readLine().split(" ");..
import sys input = sys.stdin.readline N, M = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] M, K = map(int, input().split()) B = [list(map(int, input().split())) for _ in range(M)] result = [[0 for _ in range(K)] for _ in range(N)] for n in range(N): for k in range(K): for m in range(M): result[n][k] += A[n][m] * B[m][k] for i in result: print(*i) 문제요약 행렬 곱을 진행..
import java.util.*; import java.io.*; class Main { static long P = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long K = sc.nextLong(); long A = factorial(N); long B = factorial(K) * factorial(N - K) % P; System.out.println(A * pow(B, P - 2) % P); } private static long pow(long base, long expo) { if (expo == 0) { return 1; } lo..
import sys input = sys.stdin.readline N, K = map(int, input().split()) P = 1000000007 def pow(base, expo): if expo == 0: return 1 tmp = pow(base, expo // 2) if expo % 2 == 1: return (tmp * tmp % P) * base % P else: return tmp * tmp % P def factorial(N): f = 1 while (N > 1): f = (f * N) % P N -= 1 return f # A는 분자 B는 분모 # 분자 N! A = factorial(N) # 분모 (K! * (N-K)!) mod p B = factorial(K) * factoria..