poj 2081 Recaman's Sequence (dp)
| Time Limit: 3000MS | Memory Limit: 60000K | |
| Total Submissions: 22566 | Accepted: 9697 |
Description
The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...
Given k, your task is to calculate ak.
Input
The last line contains an integer −1, which should not be processed.
Output
Sample Input
7
10000
-1
Sample Output
20
18658
Java AC 代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = 0;
int[] result;
boolean[] marked = new boolean[10000000];
while((n = sc.nextInt()) != -1) {
result = new int[n + 1];
for(int i = 1; i < n + 1; i++) {
int a = result[i - 1] - i;
if(a > 0 && !marked[a]) {
result[i] = a;
marked[a] = true;
}
else {
result[i] = a + 2 * i;
marked[a + 2 * i] = true;
}
}
System.out.println(result[n]);
for(int i = 0; i < 10000000; i++ )
marked[i] = false;
}
}
}
poj 2081 Recaman's Sequence (dp)的更多相关文章
- POJ 2081 Recaman's Sequence
Recaman's Sequence Time Limit: 3000ms Memory Limit: 60000KB This problem will be judged on PKU. Orig ...
- Poj 2081 Recaman's Sequence之解题报告
...
- poj 2081 Recaman's Sequence
開始还以为暴力做不出来,须要找规律,找了半天找不出来.原来直接暴力.. 代码例如以下: #include<stdio.h> int a[1000050]; int b[100000000] ...
- POJ 2081 Recaman's Sequence(水的问题)
[简要题意]:这个主题是很短的叙述性说明.挺easy. 不重复. [分析]:只需要加一个判断这个数是否可以是一个数组,这个数组的范围. // 3388K 0Ms #include<iostrea ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- POJ-2081 Recaman's Sequence
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22392 Accepted: 9614 D ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
随机推荐
- Volley源码分析
取消请求的源码分析: public void cancelAll(RequestFilter filter) { synchronized (mCurrentRequests) { for (Requ ...
- 七十四:flask信号之flask的内置信号
flask所有的内置信号 1.template_rendered:模板渲染完成后的信号2.before_render_template:模板渲染之前的信号3.request_started:模板开始渲 ...
- java base64相关
文件转Base64: public static String imgToBase64(InputStream inStream) { byte[] data = null; try { //avai ...
- CentOS6.5升级手动安装GCC4.8.2 转载
一.简易安装 操作环境 CentOS6.5 64bit,原版本4.4.7,不能支持C++11的特性~,希望升级到4.8.2 不能通过yum的方法升级,需要自己手动下载安装包并编译 1.1 获取安装包并 ...
- C#编程 JSON操作
JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小.更快,更易解析.JSON跟XML一样是一种是数据格式. JSON 使用 JavaScript 语法来描述数据对象,但是 ...
- Springboot 上传报错: Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceede
Failed to parse multipart servlet request; nested exception is java.lang.IllegalStateException: The ...
- Go语言入门篇-网络经验
Go语言学习手册 golang*看云 golang圣经 wuYinIO 1.go语言开发中的坑 go新手容易犯的三个致命错误 Golang 需要避免踩的 50 个坑 2.go语言数据类型 map ...
- 在phpStrom中安装php代码格式化插件Php-cs-fixer
由于phpStrom原来的插件不再开源,现在转为使用Php-cs-fixer格式化代码.以下为在phpStrom中安装Php-cs-fixer的具体步骤. 安装安装很简单,下载php-cs-fixer ...
- Linux 概念与快捷方式
概念 何为shell Shell 是指"提供给使用者使用界面"的软件(命令解析器),类似于 DOS 下的 command(命令行)和后来的 cmd.exe .普通意义上的 Shel ...
- springboot整合springdatajpa时jar冲突
1.springboot整合springdatajpa测试时报No bean named 'entityManagerFactory' available错误 2.运行springboot主程序时报以 ...