1010.Zero Escape

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.