2013
11-11

# Lucky tickets

The public transport administration of Ekaterinburg is anxious about the fact that passengers don’t like to pay for passage doing their best to avoid the fee. All the measures that had been taken (hard currency premiums for all of the chiefs, increase in conductors’ salaries, reduction of number of buses) were in vain. An advisor especially invited from the Ural State University says that personally he doesn’t buy tickets because he rarely comes across the lucky ones (a ticket is lucky if the sum of the first three digits in its number equals to the sum of the last three ones). So, the way out is found — of course, tickets must be numbered in sequence, but the number of digits on a ticket may be changed. Say, if there were only two digits, there would have been ten lucky tickets (with numbers 00, 11, …, 99). Maybe under the circumstances the ratio of the lucky tickets to the common ones is greater? And what if we take four digits? A huge work has brought the long-awaited result: in this case there will be 670 lucky tickets. But what to do if there are six or more digits?

So you are to save public transport of our city. Write a program that determines a number of lucky tickets for the given number of digits. By the way, there can’t be more than 10 digits on one ticket.

Input contains a positive even integer N not greater than 10. It’s an amount of digits in a ticket number.

Output should contain a number of tickets such that the sum of the first N/2 digits is equal to the sum of the second half of digits.

4

670

import java.util.*;
/**
*
* @author leo
*/
public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int n, max=0;
int[][] dp = new int[6][46];
for(int i=0;i<=9;i++){
dp[1][i]=1;
}
for(int i=1;i<=5;i++){
dp[i][0]=1;
}
for(int i=1;i<=5;i++){
for(int j=1;j<=i*9;j++){
if(j< 10) dp[i][j]=dp[i-1][j]+dp[i][j-1];
else dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-10];
}
}

n = sc.nextInt();
for(int i=0;i<=(n*9)/2;i++){
max+=(dp[n/2][i]*dp[n/2][i]);
}
System.out.println(max);
}
}

1. 如果两个序列的最后字符不匹配（即X [M-1]！= Y [N-1]）
L（X [0 .. M-1]，Y [0 .. N-1]）= MAX（L（X [0 .. M-2]，Y [0 .. N-1]），L（X [0 .. M-1]，Y [0 .. N-1]）
这里写错了吧。

2. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。