POJ-2346 Lucky tickets(线性DP)
来源:互联网 发布:软件培训机构排行榜 编辑:程序博客网 时间:2024/05/29 04:33
Lucky tickets
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3298 Accepted: 2174
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/2可以组成的所有数字的个数,答案就是每个数字的个数的平方和。dp[i][k]表示i位组成k的个数,用线性dp,递推就好了
#include <iostream>#include <string.h>#include <math.h>#include <algorithm>#include <stdlib.h>using namespace std;int dp[6][46];int main(){ memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<6;i++) { //j表示当前这个位上的数字 for(int j=0;j<=9;j++) { for(int k=9*i;k>=j;k--) { dp[i][k]+=dp[i-1][k-j]; } } } int n,ans; while(scanf("%d",&n)!=EOF) { n/=2; ans=0; for(int i=0;i<=45;i++) ans+=dp[n][i]*dp[n][i]; printf("%d\n",ans); } return 0;}
- POJ-2346 Lucky tickets(线性DP)
- 【POJ】2346 - Lucky tickets(数位dp)
- POJ 2346 Lucky tickets [DP]
- 据说是水DP Lucky tickets POJ 2346
- POJ 2346 Lucky tickets
- poj 2346 Lucky tickets
- POJ 2346 Lucky tickets(数位dp求前几位数字和)
- POJ 2355 Railway tickets (线性dp)
- URAL 1036 Lucky Tickets(基础dp)
- poj2346--Lucky tickets+DP
- POJ 2355 Railway tickets 线性DP
- Gym 100418J Lucky tickets(数位dp)
- URAL 1036. Lucky Tickets(dp+大数)
- URAL 1036 Lucky Tickets (高精度,数位dp)
- URAL 1036 Lucky Tickets 【dp】【高精度】
- 2346 Lucky tickets 解题报告
- lucky tickets
- HDU 1260 Tickets【线性dp】
- 杭电1863 畅通工程
- Java读取十六进制数转化为图片
- 判断是否为回文数
- Multipliers codeforces -费马小定理
- 欧拉函数
- POJ-2346 Lucky tickets(线性DP)
- caffe添加PrecisionRecallLosslayer层(一)
- bzoj1858 序列操作 线段树打标记
- #Objective - C - UI-design - 第三天 -UIKit框架-UIKit-视图控制器-注意:只有开关灯游戏内容
- SSH2框架搭建 和 配置文件详解
- Linux无密登陆
- Eclipse4.4安装旧版本插件报错 Failed to prepare partial IU
- javascript类型系统之Array
- Spark 1.6 内存管理模型( Unified Memory Management)分析