Uvalive 6884 great + SWERC = PORTO DFS Simulation

Source: Internet
Author: User

Topic Connection:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=4896

We want to has a great swerc at Porto this year and we approached this challenge in several ways.
We even framed it as a word addition problem, similar to the classic Send+more=money, where
Each letter stands for a digit (0, 1, 2, ..., 8, 9) that makes the arithmetic operation correct. Inch
Word Additions di?erent Letters cannot be assigned the same digit and the leftmost letter in a word
Cannot be zero (0). In particular, a single letter term cannot is zero.
To solve this word addition problem we had to nd positive digits for G, S and P, and digits for R,
E, A, T, W, C, O, so, all letter have A di?erent digit and the sum is correct. It turns out of that,
Unlike the classical Send+more=money which have a single solution, Great+swerc=porto
Has six solutions.
T=7, e=3, w=9, G=1, a=0, p=4, s=2, C=8, r=6, o=5
T=7, e=3, w=9, g=2, a=0, p=4, S=1, C=8, r=6, o=5
T=8, E=5, W=1, g=3, a=7, p=9, s=6, c=4, r=0, o=2
T=8, E=5, W=1, g=6, a=7, p=9, s=3, c=4, r=0, o=2
T=9, E=5, w=2, G=1, A=8, p=7, s=6, c=4, r=0, o=3
T=9, E=5, w=2, g=6, A=8, p=7, S=1, c=4, r=0, o=3
Have more than one solution does do great+swerc=porto a good problem to solve
by hand, but it was still a piece of cake for a programer. Moreover, it gives us another reason to organize
Swerc again next year and, who knows, in years to come!
Given A word addition problem, compute the number of solutions (possibly zero)

Test instructions

Give you n a string ask if you can add 1~n-1 to get nth string

You can replace a letter with a number in 0~9.

A number can replace only one letter

Different letters will not exceed 10,n no more than 10

Exercises

For each of the number of searches

Be patient and write well.

#include <bits/stdc++.h>using namespacestd;Const intN = -, M = 1e2+Ten, mod = 1e9+7, INF =2e9;typedefLong Longll;Chars[ One][ One];intcan =0, n,v[n],num[n];voidDfsintDepintLastintPintNow ) {    intf = strlen (s[n]+1); if(Dep>= (f+1)) {        if(last==0) can++; return ; } f= strlen (s[p]+1); if(p!=N) {if((F-DEP +1) >=1) {            if(V[S[P][F-DEP +1]] != -1) {                if(F-DEP +1==1&& V[S[P][F-DEP +1]]==0)return ; DFS (Dep,last,p+1, now+v[s[p][(F-DEP +1)]]); }Else {                 for(intI=0; i<=9; i++) {                    if(Num[i])Continue; if(F-DEP +1==1&&i==0)Continue; Num[i]=1; v[s[p][(f-Dep +1)]] =i; DFS (Dep,last,p+1, now+i); v[s[p][(f-Dep +1)]] = -1; Num[i]=0; }            }        }ElseDFS (dep,last,p+1, now); }Else {        if(v[s[p][(F-DEP +1)]]!=-1) {            if((f-dep+1==1) &&v[s[p][(F-DEP +1)]]==0)return ; if((now+last)%Ten! = v[s[p][(F-DEP +1)]])return ; DFS (DEP+1, (Now+last)/Ten,1,0); }        Else {            if(num[(now+last)%Ten])return ; if(dep==f&& (now+last)%Ten==0) {return ;} v[s[p][(f-Dep +1)]] = (now+last)%Ten; num[( now+last)%Ten] =1; DFS (DEP+1, (Now+last)/Ten,1,0); num[( now+last)%Ten] =0; v[s[p][(f-Dep +1)]] = -1; }    }}intMain () { while(~SCANF ("%d",&N)) { for(intI=1; i<=n;i++) scanf ("%s", s[i]+1); intMX =0;  for(intI=1; i<n;i++) {            intLen = strlen (s[i]+1); MX=Max (Mx,len); }        intMxx = strlen (s[n]+1); if(MX >mxx) {cout<<0<<Endl; Continue; } memset (num,0,sizeof(num)); memset (V,-1,sizeof(v)); Can=0; DFS (1,0,1,0); cout<<can<<Endl; }}

Uvalive 6884 great + SWERC = PORTO DFS Simulation

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.