사실 나는 SPOJ 문제를 해결하기 위해 노력하고 있습니다. [SPOJ] http://www.spoj.com/problems/SQRBR/. 나는 그것을 해결하기 위해 재발을 생각해 냈지만 나는 memoisation을하는 방법을 얻지 못하고있다. 주어진 문제에 대한 암기 방법에 대한 제안이 도움이 될 것입니다. 내 코드는 정답을주고 있지만, 내 코드는 여기에있다. 내 코드 :다음 C++ 코드에 memoisation하는 방법
#include <iostream>
#include <cstdio>
using namespace std;
void balancedParen(int n, int open, int position, int close, char str[], string s, long long int &counter) {
if(close == n) {
str[pos] = '\0';
printf("%s\n", str);
counter++;
return;
}
if(s[position] == '(') {
if(open <= n-1) {
str[position] = '(';
balancedParen(n, open+1, position+1, close, str, s, counter);
}
} else {
if(open < n) {
str[position] = '(';
balancedParen(n, open+1, position+1, close, str, s, counter);
}
if(open > close) {
str[position] = ')';
balancedParen(n, open, position+1, close+1, str, s, counter);
}
}
return ;
}
int main() {
int a[100], n, k, i;
long long counter = 0;
int testCases;
scanf("%d", &testCases);
while(testCases--) {
scanf("%d", &n);
scanf("%d", &k);
char str[100];
string s = "..........................................................................";
for(i = 0; i < k; i++) {
scanf("%d", &a[i]);
s[a[i]-1] = '(';
}
balancedParen(n, 0, 0, 0, str, s, counter);
printf("%lld\n", counter);
counter = 0;
}
return 0;
}
나는 아직도이 문제를 어떻게하는지 이해하지 못하고있다 ?? 아주 간단하고 명확한 예를 사용하여 설명해 주시겠습니까? 제게 설명해주세요, 저는이 문제에 너무 오랫동안 붙어 있습니다 !!! –
1과 7 사이에는 5, 2, 3, 4, 5, 6이 있습니다. 왜 uvent havent 2, 그리고 말해 줄 수 없다는 것입니다. 4에 대한 가능한 순열의? 14 시니? 어떻게 총계를 고려해야하는지. 가능한 유효 순열의 u는 explaination을 정교하게 할 수 있습니까, 나는 사실 어떻게 permutation 함수를 만들어야하지 않는거야? 나는 ur 도움을 위해 thankfull 일 것이다. –
필자는 예제에서 적어도 3 개의 오픈 괄호를 사용하지 않고 7 위를 차지할 방법이 없기 때문에 2를 언급하지 않았다. 예를 들어 "[] []]]"열린 괄호가 두 개 있지만 불법입니다. 설명하는 것이 좋지 않아 몇 가지 예제 코드를 추가 했으니 이제는 말하도록 할 것입니다. –