Beautiful Palindrome Number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 474 Accepted Submission(s): 301
Problem Description
A positive integer x can represent as
(a1a2…akak…a2a1)10
or
(a1a2…ak−1akak−1…a2a1)10
of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies
0<a1<a2<…<ak≤9
, we call x is a Beautiful Palindrome Number.
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10N .
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10N .
Input
The first line in the input file is an integer
T(1≤T≤7)
, indicating the number of test cases.
Then T lines follow, each line represent an integer N(0≤N≤6) .
Then T lines follow, each line represent an integer N(0≤N≤6) .
Output
For each test case, output the number of Beautiful Palindrome Number.
Sample Input
2 1 6
Sample Output
9 258
Source
BestCoder Round #13
题目大意:求取范围内的中心向两侧递减的回文数的数量
题目分析:dp求取递减串的个数
dp[i][j]:表示长度为i的以j为最大项的递减/递增串的个数
然后求和即可,
特判一下,输入0的时候输出1即可
数据水到,好像各种姿势都能过
题目大意:求取范围内的中心向两侧递减的回文数的数量
题目分析:dp求取递减串的个数
dp[i][j]:表示长度为i的以j为最大项的递减/递增串的个数
然后求和即可,
特判一下,输入0的时候输出1即可
数据水到,好像各种姿势都能过
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int t,n;
int num[10];
int dp[10][10];
int main ( )
{
scanf ( "%d" , &t );
memset ( dp , 0 , sizeof ( dp ) );
for ( int i = 1; i < 10 ; i++ )
dp[1][i] = 1;
for ( int i = 2 ; i < 10 ; i++ )
for ( int j = 1 ; j < 10 ;j++ )
for ( int k = 1 ; k < j ; k++ )
dp[i][j] += dp[i-1][k];
num[0] = 0;
for ( int i = 1 ; i < 7 ; i++ )
{
int mid = (i+1)>>1;
num[i] += num[i-1];
for ( int j = 1; j < 10 ; j++ )
num[i] += dp[mid][j];
}
while ( t-- )
{
scanf ( "%d" , &n );
if ( n == 0 ) puts ( "1" );
else printf ( "%d\n" , num[n] );
}
}