POJ 2346 Lucky tickets(数位dp求前几位数字和)
来源:互联网 发布:mmd双人动作数据下载 编辑:程序博客网 时间:2024/05/17 01:12
Lucky tickets
Time Limit: 1000MS
Memory Limit: 65536KTotal Submissions: 3376
Accepted: 2235
Memory Limit: 65536KTotal Submissions: 3376
Accepted: 2235
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.
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
Source
Ural State University Internal Contest October'2000 Students Session
题目大意:给定一个n,求n位数中有多少个数的前n/2位的和与后n/2位的和相等.
解题思路:
就是求n/2位数有多少种不同的和
1、dp[ i ][ j ]表示为第 i 位和为 j 的数有多少
2、ans为dp[ n/2 ][ 0 ~ n/2*9 ]平方和
AC代码
#include<cstdio>#include<iostream>using namespace std;int dp[6][50];void init(){dp[0][0]=1;for(int i=1;i<=5;i++){for(int j=0;j<=i*9;j++){for(int k=0;k<=9;k++){if(j>=k)dp[i][j]+=dp[i-1][j-k];}}}}int main(){init();int n;scanf("%d",&n);int sum=0;for(int i=0;i<=n/2*9;i++){sum+=dp[n/2][i]*dp[n/2][i];}printf("%d\n",sum);return 0;}
阅读全文
1 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(线性DP)
- POJ 2346 Lucky tickets
- poj 2346 Lucky tickets
- URAL 1036 Lucky Tickets (高精度,数位dp)
- 【数位DP】Codeforces Gym 100418J Lucky tickets
- Gym 100418J Lucky tickets(数位dp)
- poj2346--Lucky tickets+DP
- [SGU390]Tickets && 数位DP
- URAL 1036. Lucky Tickets(dp+大数)
- URAL 1036 Lucky Tickets(基础dp)
- URAL 1036 Lucky Tickets 【dp】【高精度】
- 2346 Lucky tickets 解题报告
- lucky tickets
- SGU 390 Tickets(数位DP)
- Linux下安装Nginx
- linux的内存管理方式
- linux下安装python3对应的setuptools、pip和其他包
- 图像分割“RefineNet-Multi-Path Refinement Networks for High-Resolution Semantic Segmentation”
- HDU--dp练习--1013--免费馅饼
- POJ 2346 Lucky tickets(数位dp求前几位数字和)
- h5 css3笔记
- HTML5 drag & drop 拖拽与拖放简介
- BUG顺口溜
- 回归问题属性的可视化
- 科技有意思丨当威风凛凛的保安机器人掉进了水里……
- bzoj3262陌上花开 cdq分治 三维偏序
- 微信公众平台开发历程(三)
- 十进制负数转换成二进制数的方法