C. Back and Forth
Editor: 최연웅(yonsweng)
문제 풀이
정답 소스 (C++)
#include <iostream>
#include <utility>
using namespace std;
int bucket1[10], bucket2[10];
bool check[1199]; // 802~1198
void back_and_forth(int barn1, int depth) {
if(depth == 2) {
check[barn1] = true;
return;
}
for(int i=0; i<10; i++) {
back_and_forth(barn1, depth + 1); // Carry bucket1[i] 1->2 and 1<-2.
for(int j=0; j<10; j++) {
swap(bucket1[i], bucket2[j]); // Carry bucket1[i] 1->2 and bucket2[j] 1<-2.
back_and_forth(barn1 + bucket1[i] - bucket2[j], depth + 1);
swap(bucket1[i], bucket2[j]);
}
}
}
int main() {
for(int i=0; i<10; i++) cin >> bucket1[i];
for(int i=0; i<10; i++) cin >> bucket2[i];
back_and_forth(1000, 0);
int answer = 0;
for(int i=802; i<=1198; i++) answer += check[i] ? 1 : 0;
cout << answer;
return 0;
}Last updated