Ask the great gods to look at this algorithm problem

Source: Internet
Author: User

Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: Problem description We call a number interesting, when and only if:
1. Its numbers contain only 0, 1, 2, 3, and these four numbers appear at least once.
2. All 0 appear before all 1, and all 2 appear before all 3.
3. The maximum number of digits is not 0.
Therefore, the smallest interesting number that conforms to our definition is 2013. In addition, the 4-bit interesting number also has two: 2031 and 2301.
Please calculate the number of interesting numbers that happen to have n bits. Because the answer can be very large, only the remainder of the output answer divided by 1000000007 is required. Input format input has only one row, including exactly a positive integer n (4≤n≤1000). Output format output has only one row, including the remainder of the number of interesting numbers in exactly n-bit integers divided by 1000000007. Example input 4 Sample output 3
Attached to my own code, my idea is based on the permutation combination:
Import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner in = new Scanner (system.in); T n = 0;long sum = 0, temp = 1;n = In.nextint (), for (int i = 1; I <= n-1; i++) for (int j = 1; J <= N-1-I; + j) for (int m = 1; M <= n-1-i-j; m++) {temp = 1;for (int a = n-1; a >= n-i-J; a--) {temp = temp * A;} for (int a = i + j; a >= 1; a--) {temp = temp/a;} sum = (sum + temp);} SYSTEM.OUT.PRINTLN (sum% 1000000007);}}

But the long type is not enough, the answer will be wrong when you calculate more than 20! Please all the way the great God to the staff and staff to guide more effective and multi-methods. I feel that my algorithm in the running time requirements or not to meet the requirements. Appreciate it!!!

Ask the great gods to look at this algorithm problem

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.