"Algorithmic Learning note" 64. Enumeration method SJTU OJ 1381 Smooth Toothpick

Source: Internet
Author: User

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

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.