ural 1586. Threeprime Numbers】的更多相关文章

题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i][j][k] 表示i位数字,最高位数字j,第二高位数字k 状态转移方程:dp[i][j][k] += dp[i-1][k][l] 注意:最高位从1开始枚举:) 详细解释:http://blog.csdn.net/zhangyanxing666/article/details/9628563 */…
题目链接 题意 : 定义Threeprime为它的任意连续3位上的数字,都构成一个3位的质数. 求对于一个n位数,存在多少个Threeprime数. 思路 : 记录[100, 999]范围内所有素数(标记的是该素数的每一位x1,x2,x3).然后从n = 4往后,定义dp[i][x2][x3],  i 表示到第 i 位时,第 i-1 位为 x2 , 第 i 位x3,此时所包含的情况数. dp[i][x2][x3] = dp[i][x2][x3] + dp[i-1][x1][x2]:最后求和sum…
这道题看着别人的代码写的. #include <cstdio> #include <cstring> #define m 1000000009 using namespace std; ][][]; ][][]; ; void getprime() { memset(dp,,sizeodp(dp)); ]; memset(p,false,sizeof(p)); ; i<; i++) { if(!p[i]) { ; j+=i) { p[j]=true; } } } ; i<…
题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 22; const int INF = 0x3f3f3f3f; long long…
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate integers together in their spare time. Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting i…
1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pages in his notebook from 1 to N. Please, figure out the number of zeros, ones, twos, …, nines he might need. Input One number N (1 ≤ N < 109). Output…
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the Internet and came across an interesting puzzle: What is the number under the car? It took some time before Pierre solved the puzzle, but eventually he u…
In the present world you frequently meet a lot of call numbers and they are going to be longer and longer. You need to remember such a kind of numbers. One method to do it in an easy way is to assign letters to digits as shown in the following pictur…
题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要用三维了就 . //URAL 1012 #include <stdio.h> #include <string.h> #include <iostream> using namespace std ; ]; ][] ; int main() { int n, k ; sca…
1118. Nontrivial Numbers Time limit: 2.0 secondMemory limit: 64 MB Specialists of SKB Kontur have developed a unique cryptographic algorithm for needs of information protection while transmitting data over the Internet. The main advantage of the algo…