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 ...
随机推荐
- Linux环境下源码安装PostgreSQL
1.下载PostgreSQL源码包,并保存到Linux操作系统的一个目录下 2.解压PostgreSQL源码包 :tar zxvf postgresql-9.2.4.tar.gz 或 tar jxvf ...
- nginx的gizp压缩
好处: 页面另存为大小比浏览器传输大小大很多.好处是加快传输.节省带宽. 原理: 浏览器 -> 请求 -> 声明可以接受的压缩方式[http 协议请 ...
- 紫书 例题 10-14 UVa 12034(组合数+递推)
这道题有点类似动态规划,设答案为f(n) 第一个人有i个人,就有c(n,i)种可能 然后后面有f(n-i)种可能,所以相乘,然后枚举所有可能加起来就ok了. #include<cstdio> ...
- 【codeforces 538E】Demiurges Play Again
[题目链接]:http://codeforces.com/problemset/problem/538/E [题意] 给你一棵树; 有两个人,分别从根节点开始,往叶子节点的方向走; 每个人每次只能走一 ...
- Mesh BRep Shapes
Mesh BRep Shapes eryar@163.com Abstract. 当对OpenCASCADE的BRep表示法的数据结构有了一定的理解后,建议可以自己实现一个显示数据生成的功能,即网格剖 ...
- IDEA创建maven项目之后无法编写java类
在创建Maven web项目之后无法再java文件夹下面创建java类,这里我可以教一下大家 选择你的文件夹,鼠标点击右键,出现下图所显示的,你可以按照下图所显示的步骤进行操作
- Visual Code中的智能提示
https://code.visualstudio.com/docs/editor/intellisense C# https://marketplace.visualstudio.com/items ...
- Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)
上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...
- JS实现页面跳转 浏览器地址栏保持不变
JS实现页面跳转 浏览器地址栏保持不变 在公司内部框架中,发现点击超链接,页面发生跳转,而浏览器地址栏URL始终保持不变.分析其实现机制,响应A标签onclick事件,通过Ajax向服务器端发送htt ...
- 【基础篇】Android手动卸载虚拟机程序
adb shell (进入模拟器自带的操作系统) cd data/app (切换到apk的安装目录) rm apk文件全称 例 : rm com.test.TestActivity.apk (手动删除 ...