题意:n个数分成两堆,每堆的原根之和的原根分别要等于给出的AB,原根如: 65536 是 7 , 6+5+5+3+6=25 然后 2+5=7 .
将其看成背包,则mod 9之后的那个值看成容量,做次背包就行了。
//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <time.h>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
///cout << fixed << setprecision(13) << (double) x << endl;
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
#define Mp(a, b) make_pair(a, b)
#define asd puts("asdasdasdasdasdf");
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair <int, int> pl;
//typedef __int64 LL;
const int inf = 0x3f3f3f3f;
const int N = 100050;
const ll mod = 258280327;
ll dp[N][10];
int a[N];
int f( int x, int y )
{
int tmp = x+y;
tmp %= 9;
return tmp ? tmp: 9;
}
int main()
{
int A, B, n;
int tot;
scanf("%d", &tot);
while( tot-- ) {
scanf("%d%d%d", &n, &A, &B);
memset( dp, 0, sizeof( dp ) );
int sum = 0;
for( int i = 1; i <= n; ++i ) {
scanf("%d", &a[i]);
sum = f( sum, a[i] );
}
for( int i = 1; i <= n; ++i )
dp[i][a[i]] = 1;
for( int i = 1; i <= n; ++i ) {
for( int j = 0; j <= 9; ++j ) {
dp[i][j] = ( dp[i][j] + dp[i-1][j] ) % mod;
int k = f( a[i], j );
dp[i][k] = (dp[i][k] + dp[i-1][j]) % mod;
}
}
ll ans = 0;
if( f( A, B ) == sum )
ans = dp[n][A];
if( B == sum )
ans++;
printf("%lld\n", ans);
}
return 0;
}
题目数据弱。。。