Enumeration method is good, reasoning is very troublesome, feel can not do it.
Create a structure, one is the real number, and the other is the number of toothpicks spent.
Build a single-digit, two-digit, three-digit number.
#include <iostream>#include<vector>using namespacestd;//the number of toothpicks that are consumed from 0 to 9intcost[Ten]={6,2,5,5,4,5,6,3,7,6};structnum{intN//the number used for the calculation intC//the cost of toothpicks};num v[100000];intMainintargcChar Const*argv[]) { intV_size =0; //One-digit for(inti =0; I <=9; ++i) {num T; T.N=i; T.C=Cost[i]; V[T.N]=T; } //two-digit number for(inti =1; I <=9; ++i) { for(intj =0; J <=9; ++j) {num T; T.N= i*Ten+J; T.C= V[i].c +v[j].c; V[T.N]=T; } } //three-digit number for(inti =1; I <=9; ++i) { for(intj =0; J <=9; ++j) { for(intk=0; K <=9; ++k) {num T; T.N= i* -+ j*Ten+K; T.C= v[i].c + v[j].c +v[k].c; V[T.N]=T; } } } intTotal =0;//total number of answersCin>>Total ; intAns =0; //Enumeration A-B calculates C and cost for(inti =999; I >=0; --i) { for(intj =0; J <= I; ++j) {intK = V[I].N-V[J].N; intCost =3+ v[i].c + v[j].c +v[k].c; if(Cost = =Total ) { //cout<<i<< "-" <<j<< "=" <<k<<endl;ans++; } }} cout<<ans<<Endl; return 0;}
"Algorithmic Learning note" 64. Enumeration method SJTU OJ 1381 Smooth Toothpick