POJ 2346:Lucky tickets
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3247 | Accepted: 2136 |
Description
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
Output
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的更多相关文章
- POJ 3393:Lucky and Good Months by Gregorian Calendar 年+星期 模拟
Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- 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 ...
- DP+高精度 URAL 1036 Lucky Tickets
题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...
- Ural 1036 Lucky Tickets
Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- 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 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- poj 2346 Lucky tickets(区间dp)
题目链接:http://poj.org/problem?id=2346 思路分析:使用动态规划解法:设函数 d( n, x )代表长度为n且满足左边n/2位的和减去右边n/2位的和为x的数的数目. 将 ...
随机推荐
- Jsp有哪些内置对象?作用分别是什么?
Page,pageContext,request,response,session,application,out,config,exception Page指的是JSP被翻译成Servlet的对象的 ...
- 回文数索引(string类erase解题)
题目描述 给定一个仅由小写字母组成的字符串.现在请找出一个位置,删掉那个字母之后,字符串变成回文.请放心总会有一个合法的解.如果给定的字符串已经是一个回文串,那么输出-1. 输入描述: 第一行包含T, ...
- #$d#$a什么意思
#$d#$a什么意思 qjh.693111级分类:外语被浏览37次2013.05.12 满意答案 vgrwi 采纳率:50%12级 2013.05.13 回车换行 换成十进制就是 #13#10
- Arch-base-vs-iso
Arch-base-vs-iso 通常绝大多数的Linux分发版的iso镜像本身(*.iso文件都有约2Gb上下)都可以直接启动电脑并运行完整的Linux桌面系统. 极少数的Linux发行版仅提供命令 ...
- MongoDB首次启动常见问题
问题1. exception in initandlisten 29 data directory /data/db not found 问题:MongoDB默认存储路径为/data/db,这里显示没 ...
- 020、MySQL创建一个存储过程,显示存储过程,调用存储过程,删除存储过程
一.我们创建一个MySQL储存过程,在SQL代码区写入以下内容,并执行就可以了 #编写一个存储过程 CREATE PROCEDURE ShowDate ( ) BEGIN #输出当前时间 SELECT ...
- Python 常用的标准库以及第三方库有哪些?
作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- 软件包管理:RPM包管理-yum在线管理
CentOS 是免费的的 RedHat需要付费 1.IP地址配置 setup #使用setup工具 (这种方式配置的永久有效 同时还可以配置掩码 网关等) 直接输入setup就会弹出(注意的是该命令 ...
- P1051复数乘法
P1051复数乘法 转跳点:
- maven集成SSM项目,Tomcat部署运行——SSM整合框架搭建(二)之问题
问题一.当放开controller中的方法,出现如下问题 ### Error querying database. Cause: org.springframework.jdbc.CannotGetJ ...