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 ...
随机推荐
- css inline-block列表布局
一.使用inline-block布局 二.多列布局方法二 <html><head> <meta charset="utf-8"> <tit ...
- php修改限制上传文件大小
win下: 1.编辑 php.ini:修改在 php5 下文件大小的限制 找到:file_uploads=On 允许 HTTP 文件上传 找到:max_execution_t ...
- 前端之HTTP协议
HTTP协议简介 作为学习前端开发的开始,我们必须搞明白以下几件事 1.什么是互联网 互联网=物理连接介质+互联网协议 2.互联网建立的目的? 数据传输打破地域限制,否则的话,我想获 ...
- [Poi] Customize Babel to Build a React App with Poi
Developing React with Poi is as easy as adding the babel-preset-react-appto a .babelrc and installin ...
- cigarette
#include<iostream> using namespace std; int main() { int N; cin>>N; while(N--) { int Who ...
- redis之字符串命令源代码解析(二)
形象化设计模式实战 HELLO!架构 redis命令源代码解析 在redis之字符串命令源代码解析(一)中讲了get的简单实现,并没有对 ...
- PIO Core
PIO核概述 具有Avalon接口的并行输入/输出(parallel input/output - PIO)核,在Avalon存储器映射(Avalon Memory-Mapped Avalon-MM) ...
- BZOJ5204: [CodePlus 2018 3 月赛]投票统计
[传送门:BZOJ5204] 简要题意: 有n个选手,每个选手会选择一道题投票,求出投票最多的题目个数和这些题目的编号,如果所有题目的投票数相同,则输出-1 题解: 直接搞 离散化,然后判断就可以了 ...
- Create the Data Access Layer
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...
- VS链接数据库
可以用VS链接数据库,并进行数据库操作.前提是安装了Sqlserver,活着连接线上的数据库服务器.