POJ 2346:Lucky tickets

Lucky tickets
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3247   Accepted: 2136

Description

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

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

Output

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.

Sample Input

4

Sample Output

670

题意是要找幸运数字,所谓幸运数字就是一个n位(n为偶数)的数字,前n/2位每位的数字和与后n/2位的数字和相等。

因为这题第一位0也包括进去了,题目难度减少好多。

然后一看n最大才10,难度一下子下降更多了。就不管dp了,直接打表暴力。

幸好是最大是10,电脑跑了一会才有结果。要是12估计电脑都会跑好久。

暴力代码(n为10时):

#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,result=0;
	for(i1=0;i1<=9;i1++)
		for(i2=0;i2<=9;i2++)
			for(i3=0;i3<=9;i3++)
				for(i4=0;i4<=9;i4++)
					for(i5=0;i5<=9;i5++)
						for(i6=0;i6<=9;i6++)
							for(i7=0;i7<=9;i7++)
								for(i8=0;i8<=9;i8++)
									for(i9=0;i9<=9;i9++)
										for(i10=0;i10<=9;i10++)
											if(i1+i2+i3+i4+i5==i6+i7+i8+i9+i10)
												result++;
	cout<<result<<endl;

	system("pause");
	return 0;
}


打表代码:

#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int result[12],n;
	result[0]=0;
	result[2]=10;
	result[4]=670;
	result[6]=55252;
	result[8]=4816030;
	result[10]=432457640;

	cin>>n;
	cout<<result[n]<<endl;

	return 0;
}
这么一看这道题还真是水啊。。。



版权声明:本文为博主原创文章,未经博主允许不得转载。

posted on 2015-07-11 15:48  光速小子  阅读(175)  评论(0编辑  收藏  举报

导航