※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 11523번 문제인 Running Steps이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/11523 

 

11523번: Running Steps

For each data set there is a single line of output. The single output line consists of the data set number, K, followed by a single space followed by the number of different ways of running the steps that satisfy the coach’s four criteria.

www.acmicpc.net

왼발의 step stride의 개수를 k로 정한다면, 문제의 조건에 따라 오른 발의 step stride 개수 또한 k가 된다. 그리고, 각 발의 1-step stride의 개수와 2-step stride의 개수 또한 정해지게 된다.

 

1-step stride보다 2-step stride의 개수가 적지 않은 각 경우에 대하여 해당 stride들을 나열하는 경우의 수를 조합을 이용해 계산하여 둘을 곱한 값을 누적하는 것으로 문제의 답을 구해내자.

 

문제의 답이 int범위를 넘을 수 있음에 유의하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;
typedef long long ll;

ll comb[70][70];

ll ans[101];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	for (int n = 0; n < 70; n++) {
		comb[n][0] = comb[n][n] = 1;
		for (int r = 1; r < n; r++) {
			comb[n][r] = comb[n - 1][r - 1] + comb[n - 1][r];
		}
	}

	for (int n = 1; n < 51; n++) { // n: 한쪽 다리 스텝 횟수
		for (int j = n / 2; j > -1; j--) { // j: two step strides 개수
			int i = n - j * 2;
			if (i > j) break;
			ans[n * 2] += comb[i + j][i] * comb[i + j][i];
		}
	}

	int P; cin >> P;
	while (P--) {
		int p, x; cin >> p >> x;
		cout << p << ' ' << ans[x] << '\n';
	}
}
728x90

+ Recent posts