Bzoj 1008: [hnoi2008] jailbreak [combination]

Source: Internet
Author: User
There are few ideas to explain in seconds. It can be described that there are m dyeing schemes for the lattice with a length of N in pairs. If there are two adjacent grids with the same color, it is difficult to solve the problem, consider that any two adjacent grids on the back of the problem have different colors. The first lattice can be painted with any color M, n-1-1 grids cannot be the same as the previous one. The total number of grids is m ^ N. Therefore, the answer is m ^ N-M (m-1) ^ n-1 because of the high modulo and power of answers, you can consider the tip horse theorem or quick power optimization.

Because the data is too 2, the int reading at the beginning successfully contributed 3 wa Tat

 

# Include <iostream>

# Include <cstdio>

# Include <math. h>

Using namespace STD;

Long long KSM (long K, long)

{

If (k = 0) return 1;

If (k = 1) return;

If (K % 2 = 0) return KSM (K/2, a) * KSM (K/2, a) % 100003;

Else return (KSM (K-1, A) * A) % 100003;

}

Int main ()

{

Long long m = 0, n = 0, ans;

Scanf ("% LLD", & M, & N );

Ans = (KSM (n, m)-(M * KSM (N-1 m-1) % 100003 + 100003) % 100003;

Printf ("% LLD", ANS );

Return 0;

}

Bzoj 1008: [hnoi2008] jailbreak [combination]

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.