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;
}

这么一看这道题还真是水啊。。。

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

POJ 2346:Lucky tickets的更多相关文章

  1. POJ 3393:Lucky and Good Months by Gregorian Calendar 年+星期 模拟

    Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  2. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  3. CF1096. G. Lucky Tickets(快速幂NTT)

    All bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k dec ...

  4. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  5. Ural 1036 Lucky Tickets

    Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...

  6. POJ-2346 Lucky tickets(线性DP)

    Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...

  7. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  8. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  9. poj 2346 Lucky tickets(区间dp)

    题目链接:http://poj.org/problem?id=2346 思路分析:使用动态规划解法:设函数 d( n, x )代表长度为n且满足左边n/2位的和减去右边n/2位的和为x的数的数目. 将 ...

随机推荐

  1. Android中ListView结合CheckBox判断选中项

    本文主要实现在自定义的ListView布局中加入CheckBox控件,通过判断用户是否选中CheckBox来对ListView的选中项进行相应的操作.通过一个Demo来展示该功能,选中ListView ...

  2. struts2--验证器

    1.输入验证: --struts2提供了一些基于Xwork Validation Framework的内建验证程序,使用这些验证程序不需要变编程,只要在一个XML文件里进行声明,声明的内容如下: &g ...

  3. 《Netlogo多主体建模入门》笔记4

    4- 从Langton的蚂蚁看Turtle与Patch的交互   这只蚂蚁从10000步开始,就会自发地 “建桥”     Turtle与Patch就好比是,一个方块和一个格子的关系. 一个格子上可以 ...

  4. docker for windows 容器内网通过独立IP直接访问的方法

    Docker官方推荐我们通过端口映射的方式把Docker容器的服务提供给宿主机或者局域网其他容器使用.一般过程是: 1.Docker进程通过监听宿主机的某个端口,将该端口的数据包发送给Docker容器 ...

  5. Centos7 下vmware NAT模式配置网络连接与DNS

    NAT模式配置网络 1.首先查看NAT模式下的网络 从这边可以知道我的vmware下的nat模式的网络是192.168.109.*网段 上图这个网段也可以修改为别的网段 2.NAT模式下的网关 3.配 ...

  6. windowsService 程序

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. AssetBundle打包依赖(宽宽又欠我一顿烧烤)

    using UnityEngine; using System.Collections; using UnityEditor; public class dabao : EditorWindow { ...

  8. thinkphp的增删改查命令 - (mysql-thinkphp) (4)

    方法1,在namespace下面加2行 use think\Controller; use think\Db; 1.查询所有结果 $res = Db::query("select * fro ...

  9. sqli-labs level 2

    来到第第二关 首先在后面添加一个 单引号看下报错信息 发现这里多多了一个引号  尝试去掉单引号看下回显结果   :    and 1=2 可以发现这里不需要添加单引号进行闭合,可以直接控制,所以接下来 ...

  10. android中的简单animation(一)shake

    1.shake animation_1.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...