标签:
Time Limit: 3000MS | Memory Limit: 60000K | |
Total Submissions: 22566 | Accepted: 9697 |
Description
Input
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)
标签:
原文地址:http://www.cnblogs.com/kkkkkk/p/5547104.html