暴力搜索
参考中山大学大牛代码
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<set>
#define REP(i, n) for(int i=0; i<n; i++)
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int, int>
#define xx first
#define yy second
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("****debug****")
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1000010;
const int maxn = 100010;
int m, b[16];
bool dfs(int a[], int n)
{
if (n == m)
{
bool ok = true;
REP(i, m) if (a[i] != b[i]) { ok = false; break;}
if (ok) return true;
ok = true;
REP(i, m) if (a[m - i - 1] != b[i]) { ok = false; break;}
return ok;
}
int c[16], cnt;
for (int i = 0; i < n - 1; i++)
{
cnt = 0;
int j, k;
for (j = i, k = i + 1; j >= 0 && k < n; j--, k++)
c[cnt++] = a[j] + a[k];
while (j >= 0) c[cnt++] = a[j--];
while (k < n) c[cnt++] = a[k++];
if (cnt < m) continue;///不能break
if (dfs(c, cnt)) return true;
}
return false;
}
int main()
{
int a[16], n;
while (~scanf("%d", &n))
{
REP(i, n) scanf("%d", &a[i]);
scanf("%d", &m);
REP(i, m) scanf("%d", &b[i]);
if (dfs(a, n)) puts("S");
else puts("N");
}
return 0;
}