1010.Zero Escape
The number root of a number is only related to the value after its mod~9 m o d 9, as long as the backpack can complete the calculation of the personnel assignment.
Concrete Proof: Digital root =\sum_{i=0}^{w}a_i∑?I=0?W??A?I??, Number =\sum_{i=0}^{w}10^i*a_i∑?I=0?w?? 10? I?? ∗a? I??
Number-Number root =\SUM_{I=0}^{W} (10^i-1) *a_i∑?I=0?W??(10?I??−1)∗A? i ??, this number in modmod 99 domain 0 < Span class= "Mord" >0
Time complexity o (n) o ( Span class= "Mord mathit" >n)
#include <bits/stdc++.h> #define N 100010#define LL long long#define MOD 258280327using namespace Std;int a[n];int dp N [10];int Main () {int t,n,a,b,sum; scanf ("%d", &t); while (t--) {sum=0; scanf ("%d%d%d", &n,&a,&b); for (int i=1;i<=n;i++) {scanf ("%d", &a[i]); Sum= (Sum+a[i])%9; if (sum==0) sum=9; } memset (Dp,0,sizeof (DP)); Dp[1][a[1]]=1; for (int i=2;i<=n;i++) for (int j=1;j<=9;j++) {if (J>a[i]) dp[i][j]= (dp[i-1 ][j]+dp[i-1][j-a[i]])%mod; else {dp[i][j]= (Dp[i-1][j]+dp[i-1][j+9-a[i]])%mod; if (J==a[i]) dp[i][j]= (dp[i][j]+1)%mod; }} LL ans=0; int tmp= (a+b)%9; if (tmp==0) tmp=9; if (tmp==sum) {ans=dp[n][a]; if (sum==a) ans--; } if (Sum==a) ans= (ans+1)%moD if (sum==b) ans= (ans+1)%mod; printf ("%i64d\n", ans); }}
1010.Zero Escape