URAL 1586 Threeprime Numbers(DP)
题意 : 定义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(dp[n][x2][x3]);
//
#include <cstdio>
#include <cstring>
#include <iostream>
#define MOD 1000000009
#define LL long long
using namespace std ; int dp[][][],prime[][][] ;
int vis[] = {} ,cnt = ; void solve()
{
cnt = ;
memset(vis,,sizeof(vis)) ;
for(int i = ; i <= ; i++)
{
if(!vis[i])
{
for(int j = i*i ; j <= ; j += i)
vis[j] = ;
}
}
for(int i = ; i <= ; i ++)
{
if(!vis[i])
{
int x1 = i / ;
int x2 = i / % ;
int x3 = i % ;
prime[x1][x2][x3] = ;
dp[][x2][x3] += ;
cnt ++ ;
}
}
}
int main()
{
int n ;
scanf("%d",&n);
solve() ;
if(n == ) {
printf("%d\n",cnt % MOD) ;
return ;
}
for(int i = ; i <= n ; i++)
for(int x1 = ; x1 <= ; x1 ++)
for(int x2 = ; x2 <= ; x2 ++)
for(int x3 = ; x3 <= ; x3 ++)
if(dp[i-][x1][x2] && prime[x1][x2][x3])
dp[i][x2][x3] = (dp[i][x2][x3] + dp[i-][x1][x2]) % MOD;
int ans = ;
for(int x2 = ; x2 <= ; x2 ++)
{
for(int x3 = ; x3 <= ; x3 ++)
{
ans = (ans+dp[n][x2][x3])%MOD ;
}
}
printf("%d\n",ans) ;
return ;
}
URAL 1586 Threeprime Numbers(DP)的更多相关文章
- 递推DP URAL 1586 Threeprime Numbers
题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i ...
- URAL 1009 K-based numbers(DP递推)
点我看题目 题意 : K进制的N位数,不能有前导零,这N位数不能有连续的两个0在里边,问满足上述条件的数有多少个. 思路 : ch[i]代表着K进制的 i 位数,不含两个连续的0的个数. 当第 i 位 ...
- Gym 100703G---Game of numbers(DP)
题目链接 http://vjudge.net/contest/132391#problem/G Description standard input/outputStatements — It' s ...
- URAL 1146 Maximum Sum(DP)
Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...
- POJ1338Ugly Numbers(DP)
http://poj.org/problem?id=1338 第一反应就是DP,DP[i] = min{2*DP[j], 3*DP[k], 5*DP[p] j,k,p<i};于是枚举一下0-i- ...
- Ural 1073 Square Country (DP)
题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...
- Codeforces 403D: Beautiful Pairs of Numbers(DP)
题意:转换模型之后,就是1~n个数中选k个,放到一个容量为n的背包中,这个背包还特别神奇,相同的物品摆放的位置不同时,算不同的放法(想象背包空间就是一个长度为n的数组,然后容量为1的物体放一个格子,容 ...
- Ural 2018The Debut Album(DP)
题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...
- URAL 2031. Overturned Numbers (枚举)
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...
随机推荐
- Oracle 将普通表转换为分区表
DB:11.2.0.30 将普通表转换为区分表 一.利用原表重建分区表SQL>create table yoon ( id number primary key ,time date ); Ta ...
- oracle 查询今天哪个表增加的数据多
一.创建一个表 create table A( TABLE_NAME VARCHAR2(200), COUNT_NUM NUMBER) 二.创建一个存储过程create or replace ...
- Android HTTP session && cookie
HTTP协议与状态保持HTTP协议本身是无状态的,这与HTTP协议本来的目的是相符的,客户端只需要简单的向服务器请求下载某些文件,无论是客户端还是服务器都没有必要纪录彼此过去的行为,每一次请求之间都是 ...
- Linux获取线程tid线程名
Linux获取线程tid线程名 1 2 3 4 5 6 //thread name char cThreadName[32] = {0}; prctl(PR_GET_NAME, (unsigned l ...
- iOS学习之UI可视化编程-StoryBoard
一.StoryBoard与xib 对比: 相同点:都属于IB编程的方式,可以快速构建GUI. 不同点:xib侧重于单文件(单独的控制器或者视图)编辑,storyboard侧重于多页面关联.storyb ...
- iOS Bluetooth Reconnect
蓝牙的重连主要分为以下两种: 1.恢复一些已知的设备,已知的设备就是在此次操作之前你扫描到的或者已经连接过的设备.用retrievePeripheralsWithIdentifiers:函数去完成回复 ...
- firebreath 在谷歌和火狐浏览器下的调试 以及打包
在寻找插件开发资料的过程中找到了一个开发浏览器插件的开源项目——firebreath firebreath的安装以及测试我就不再叙述了,可以参考大神的文章 . http://www.blogjava. ...
- Matlab实现加性高斯白噪声信道(AWGN)下的digital调制格式识别分类
Matlab实现加性高斯白噪声信道(AWGN)下的digital调制格式识别分类 内容大纲 加性高斯白噪声信道(AWGN)下的digital调制格式识别分类 (1. PSK; 2. QPSK; 3.8 ...
- Ubuntu系统安装配置Pintos和Bochs
Ubuntu系统安装配置 Pintos 和 Bochs 安装过程 首先是UEFI启动模式下Win8.1安装Ubuntu14.04双系统,由于篇幅过长,就不在这里详写.可见博主的另一篇博客http:// ...
- 28335 sci fifo send
#include "DSP2833x_Device.h"#include "DSP2833x_Examples.h"char buf[]={0x30,0x32, ...