ural 1586. Threeprime Numbers
这道题看着别人的代码写的。
#include <cstdio>
#include <cstring>
#define m 1000000009
using namespace std; bool prime[][][];
int dp[][][];
int temp=; void getprime()
{
memset(dp,,sizeodp(dp));
bool p[];
memset(p,false,sizeof(p));
for(int i=; i<; i++)
{
if(!p[i])
{
for(int j=i+i; j<; j+=i)
{
p[j]=true;
}
}
}
for(int i=; i<; i++)
{
if(!p[i])
{
int x1=i/;
int x2=(i/)%;
int x3=i%;
prime[x1][x2][x3]=true;
dp[][x2][x3]+=;
temp++;
}
}
}
int main()
{
int n;
scanf("%d",&n);
getprime();
if(n==)
{
printf("%d\n",temp);
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])%m;
}
}
}
}
}
int ans=;
for(int x2=; x2<; x2++)
{
for(int x3=; x3<; x3++)
{
ans=(ans+dp[n][x2][x3])%m;
}
}
printf("%d\n",ans);
return ;
}
ural 1586. Threeprime Numbers的更多相关文章
- 递推DP URAL 1586 Threeprime Numbers
题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i ...
- URAL 1586 Threeprime Numbers(DP)
题目链接 题意 : 定义Threeprime为它的任意连续3位上的数字,都构成一个3位的质数. 求对于一个n位数,存在多少个Threeprime数. 思路 : 记录[100, 999]范围内所有素数( ...
- 递推DP URAL 1009 K-based Numbers
题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #in ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 1150. Page Numbers
1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...
- URAL 2031. Overturned Numbers (枚举)
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...
- URAL 1002 Phone Numbers(KMP+最短路orDP)
In the present world you frequently meet a lot of call numbers and they are going to be longer and l ...
- URAL 1012 K-based Numbers. Version 2(DP+高精度)
题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...
- ural 1118. Nontrivial Numbers
1118. Nontrivial Numbers Time limit: 2.0 secondMemory limit: 64 MB Specialists of SKB Kontur have de ...
随机推荐
- poj2063 Investment(多次完全背包)
http://poj.org/problem?id=2063 多次完全背包~ #include <stdio.h> #include <string.h> #define MA ...
- rsyslog 直接kill进程,在重新启动会全部发送日志
<pre name="code" class="html">jrhapt11:/root# ps -ef | grep rsyslog root 8 ...
- delphi7编写客户端调用java服务器端webservice示例
1. 首先取得java-webservice服务器端地址.我的是:http://localhost:8080/mywebservice/services/mywebservice?wsdl 2. 然后 ...
- 移动web app开发框架
文章地址:http://www.cnblogs.com/soulaz/p/5586787.html jQuery Mobile jQuery Mobile框架能够帮助你快速开发出支持多种移动设备的Mo ...
- 我为什么要再给lua写一个json模块
最近要给自己编写的服务器加上json解析模块.根据我当前的项目,可以预测服务器中使用json的地方: 通信.由于与客户端通信使用google protocolbuffer,仅在与SDK通信中使用jso ...
- (转)How to renew your Apple Push Notification Push SSL Certificate
转自:https://blog.serverdensity.com/how-to-renew-your-apple-push-notification-push-ssl-certificate/ It ...
- 探究css !important的应用之道
定义及语法: !important是CSS1就定义的语法,作用是提高指定样式规则的应用优先权. 语法格式:{ cssRule !important },即将!important写在定义的最后面, 例如 ...
- android之字体阴影效果
今天刚刚好做了个字体阴影的效果,感觉加上了阴影的效果立体感十足啊!写了个简单的demo与大家分享下!主要是以下四个属性 android:shadowColor 阴影的颜色 android:shad ...
- dojo 学习笔记之dojo.query - query(id) 与query(class)的差别
考虑这个样例:动态创建一个页面的时候,用new listtem()生成多个listitem, 且每一个listitem中都生成一个按钮button. 假设想要给每一个按钮都绑定一个click事件,用d ...
- ibatis的selectkey
在使用ibatis插入数据进数据库的时候,会用到一些sequence的数据,有些情况下,在插入完成之后还需要将sequence的值返回,然后才能进行下一步的操作. 使用ibatis的sel ...