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