-
Notifications
You must be signed in to change notification settings - Fork 0
/
10942.cpp
37 lines (32 loc) · 766 Bytes
/
10942.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cstdio>
#include <cstring>
int numbers[2001];
int dp[2001][2001];
int solve(int start,int end){
if(start == end){
return 1;
}
if(end-start == 1){
if(numbers[start] == numbers[end]) return 1;
else return 0;
}
int& ans = dp[start][end];
if(ans != -1) return ans;
if(numbers[start] != numbers[end]) return ans = 0;
else return ans = solve(start+1,end-1);
}
int main(){
int n,question;
scanf("%d",&n);
for(int r=1;r<=n;r++){
scanf("%d",&numbers[r]);
}
memset(dp,-1,sizeof(int)*2001*2001);
scanf("%d",&question);
for(int i=1;i<=question;i++){
int start,end;
scanf("%d %d",&start,&end);
printf("%d\n",solve(start,end));
}
return 0;
}