Gym 100952 H. Special Palindrome
http://codeforces.com/gym/100952/problem/H
1 second
64 megabytes
standard input
standard output
A sequence of positive and non-zero integers called palindromic if it can be read the same forward and backward, for example:
15 2 6 4 6 2 15
20 3 1 1 3 20
We have a special kind of palindromic sequences, let's call it a special palindrome.
A palindromic sequence is a special palindrome if its values don't decrease up to the middle value, and of course they don't increase from the middle to the end.
The sequences above is NOT special, while the following sequences are:
1 2 3 3 7 8 7 3 3 2 1
2 10 2
1 4 13 13 4 1
Let's define the function F(N), which represents the number of special sequences that the sum of their values is N.
For example F(7) = 5 which are : (7), (1 5 1), (2 3 2), (1 1 3 1 1), (1 1 1 1 1 1 1)
Your job is to write a program that compute the Value F(N) for given N's.
The Input consists of a sequence of lines, each line contains a positive none zero integer N less than or equal to 250. The last line contains 0 which indicates the end of the input.
Print one line for each given number N, which it the value F(N).
- 1
3
7
10
0
- 1
2
5
17- 动态规划题目,动态规划不是很懂,此代码是参考大牛的代码敲得,自己过时是打表过的。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <cmath>
- #include <map>
- #include <set>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define lowbit(x) (x&(-x))
- #define max(x,y) (x>y?x:y)
- #define min(x,y) (x<y?x:y)
- #define MAX 100000000000000000
- #define MOD 1000000007
- #define PI 3.141592653589793238462
- #define INF 0x3f3f3f3f3f
- #define mem(a) (memset(a,0,sizeof(a)))
- typedef long long ll;
- ll dp[][];
- ll vis[],n;
- void init()
- {
- dp[][]=dp[][]=dp[][]=;
- dp[][]=dp[][]=dp[][]=;
- vis[]=;vis[]=vis[]=;
- for(int i=;i<=;i++)
- {
- ll ans=;
- for(int j=;j<=i/;j++)
- {
- if(j==) dp[i][j]=vis[i-];
- else
- {
- ll pos=i-j*;
- if(pos==) dp[i][j]=;
- else
- {
- ll cnt=;
- for(int k=j;k<=pos;k++)
- {
- cnt+=dp[pos][k];
- }
- dp[i][j]=cnt;
- }
- }
- ans+=dp[i][j];
- }
- dp[i][i]=;
- ans+=;
- vis[i]=ans;
- }
- }
- int main()
- {
- init();
- while(scanf("%lld",&n) && n)
- {
- printf("%lld\n",vis[n]);
- }
- return ;
- }
再来一个打表代码
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <cmath>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define lowbit(x) (x&(-x))
- #define max(x,y) (x>y?x:y)
- #define min(x,y) (x<y?x:y)
- #define MAX 100000000000000000
- #define MOD 1000000007
- #define PI 3.141592653589793238462
- #define INF 0x3f3f3f3f3f
- #define mem(a) (memset(a,0,sizeof(a)))
- typedef long long ll;
- ll n;
- ll vis[]={,,,,,,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,,,,,,
- ,,,,,,,,,,,,,,
- ,,,,,,,,,,,
- ,,,,,,,,,,,
- ,,,,,,,,,,,,,,
- ,,,,,,,,,
- ,,,,,,,,
- ,,,,,,,,,,,,,
- ,,,,,,,,,
- ,,,,,,,,,,,,,
- ,,,,,,,,,,,
- ,,,,,,,,,,,
- ,,,,,,,,,
- ,,,,,,,,};
- int main()
- {
- while(scanf("%lld",&n) && n)
- {
- cout<<vis[n-]<<endl;
- }
- return ;
- }
Gym 100952 H. Special Palindrome的更多相关文章
- Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】
H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...
- codeforces gym 100952 A B C D E F G H I J
gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...
- Gym 100952 C. Palindrome Again !!
http://codeforces.com/gym/100952/problem/C C. Palindrome Again !! time limit per test 1 second memor ...
- Gym 100952 D. Time to go back(杨辉三角形)
D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...
- Gym 100952 G. The jar of divisors
http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...
- Gym 100952 F. Contestants Ranking
http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...
- Gym 100952 D. Time to go back
http://codeforces.com/gym/100952/problem/D D. Time to go back time limit per test 1 second memory li ...
- codeforces Gym 100187H H. Mysterious Photos 水题
H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
随机推荐
- <Sicily>Inversion Number(线段树求逆序数)
一.题目描述 There is a permutation P with n integers from 1 to n. You have to calculate its inversion num ...
- Bayes++ Library入门学习之熟悉class-Importance_resampler
接下来,需要介绍的是重要性重采样类Bayesian_filter::Improtance_resampler.该类实现了两种重采样方法[1][2],和其子类的继承关系图如下: 其中Standard_r ...
- Linux 下易用的光盘镜像管理工具(虚拟光驱软件)转载
作者: Frazer Kline | 2014-11-23 11:07 评论: 4 收藏: 4 分享: 10 磁盘镜像包括了整个磁盘卷的文件或者是全部的存储设备的数据,比如说硬盘,光盘(DVD,C ...
- mongodb 的索引
索引加快了查询速度,但是降低了写入速度.所以不要在没必要的属性上加索引. 在 mongodb 中索引可以按倒序/正序创建,便于排序. ...
- Python解析Socket数据流异常bytes问题
Python解析Socket数据流异常bytes问题 -- 2019-03-12 python在通过socket发送数据时,英文字符转义后为原来本身的字符,占一个字节(如:s转移后为s),而中文字符在 ...
- Python组织文件 实践:拷贝某种类型的所有文件
#! python3 #chapter09-test01- 遍历目录树,查找特定扩展名的文件不论这些文件的位置在哪里,都将他们 #拷贝到一个新的文件夹中 import os,shutil,pprint ...
- 洛谷P5082 成绩
原来的空间限制是5MB,其实是很足够的,现在调成128MB,变成了没有思维难度的大水题. 不过,我还是想说一下空间限制为5MB的解题思路. 题目要求的是(每一科的满分之和*3-每一科的实际得分之和*2 ...
- BZOJ1685: [Usaco2005 Oct]Allowance 津贴
[传送门:BZOJ1685] 简要题意: 贝西工作勤勤恳恳,她每月向约翰索要C 元钱作为工资.约翰手上有不少钱,他一共有N 种面 额的钞票.第i 种钞票的面额记作Vi,约翰有Ki 张.钞票的面额设定是 ...
- Visual Code的调试
Run 'Debug: Download .NET Core Debugger' in the Command Palette or open a .NET project directory to ...
- netsh http的使用
1.首先通过cmd进入 C:\Windows\System32\inetsrv>netshnetsh>http netsh http> 退出的时候,使用exit命令 2.显示监听的i ...