加维降复杂度

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int mod=;
int T,n,m,k,q,g[maxn][maxn],w[maxn],f[maxn][maxn][maxn][]; bool check(int a,int b,int c)
{
if(abs(w[a]-w[b])>k) return ;
if(abs(w[a]-w[c])>k) return ;
if(abs(w[b]-w[c])>k) return ;
return ;
} int main()
{
scanf("%d",&T); while(T--)
{
scanf("%d%d%d%d",&n,&m,&k,&q);
memset(g,,sizeof g);
for(int i=;i<=n;i++) scanf("%d",&w[i]);
for(int i=;i<=m;i++)
{
int u,v; scanf("%d%d",&u,&v);
g[u][v]=;
}
memset(f,,sizeof f);
for(int i=n;i>=;i--)
{
for(int j=n;j>=;j--)
{
for(int k=n;k>=;k--)
{
if(check(i,j,k)==) f[i][j][k][]=;
else f[i][j][k][]=(f[i][j][k][]+)%mod; for(int s=;s<k;s++)
if(g[s][k]) f[i][j][s][]=(f[i][j][s][]+f[i][j][k][])%mod; for(int s=;s<=j;s++)
if(g[s][j]) f[i][s][k][]=(f[i][s][k][]+f[i][j][k][])%mod; for(int s=;s<=i;s++)
if(g[s][i]) f[s][j][k][]=(f[s][j][k][]+f[i][j][k][])%mod;
}
}
} for(int i=;i<=q;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
printf("%d\n",f[a][b][c][]);
}
}
return ;
}

HDU 5807 Keep In Touch的更多相关文章

  1. HDU 5807 Keep In Touch DP

    Keep In Touch Problem Description   There are n cities numbered with successive integers from 1 to n ...

  2. Hdu 5361 In Touch (dijkatrs+优先队列)

    题目链接: Hdu 5361  In Touch 题目描述: 有n个传送机排成一排,编号从1到n,每个传送机都可以把自己位置的东西传送到距离自己[l, r]距离的位置,并且花费c,问从1号传送机到其他 ...

  3. HDU 5361 In Touch (2015 多校6 1009 最短路 + 区间更新)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:最短路.求源点到全部点的最短距离.但与普通最短路不同的是,给出的边是某点到区间[l,r]内随意 ...

  4. 2015 Multi-University Training Contest 6 hdu 5361 In Touch

    In Touch Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  5. hdu 5533 Dancing Stars on Me 水题

    Dancing Stars on Me Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  6. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  7. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  8. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  9. HDU 5515 Game of Flying Circus 二分

    Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

随机推荐

  1. C#中string的小结

    C#中的string类型明确定义为引用类型,但是使用时常常表现出数值型的特性.最典型的例子就是交换字符串. public static void stringexchange(string a, st ...

  2. 使用vs2010打开VS2013的工程文件

    在开发团队,会出现vs工具使用版本的不一样的情况.我的电脑使用的是VS2010,可是其他人员使用的是vs2013. 要打开其他人员上传的工程文件,可以通过三种方式: 1.下载一个vs2013版本. 2 ...

  3. Spring.net 学习IOC------属性注入

    我们就完成我们的第一个spring.net学习IOC的"hello world!". 1> 我们新建一个C# 的控制台项目名为Spring,然后引入Spring.Core.d ...

  4. 【转】Freemarker输出$和html标签等特殊符号

    原文:http://blog.csdn.net/achilles12345/article/details/41820507 场景:程序员都不喜欢看文档,而更喜欢抄例子.所以,我们把平台组的组件都做成 ...

  5. React源码解析-Virtual DOM解析

    前言:最近一直在研究React,看了陈屹先生所著的深入React技术栈,以及自己使用了这么长时间.对React应该说有比较深的理解了,正好前阵子也把两本关于前端设计模式的书看完了,总感觉有一种知识错综 ...

  6. html5权威指南:客户端分区响应图

    客户端分区响应图:http://www.cnblogs.com/enjoymylift/p/5984338.html

  7. display: inline-block兼容性写法

    display:inline-block;*display:inline;*zoom:1;

  8. Hadoop安装教程

    单机.伪分布式:http://dblab.xmu.edu.cn/blog/install-hadoop/ 集群:http://dblab.xmu.edu.cn/blog/install-hadoop- ...

  9. Linux shell 操作 postgresql,并设置crontab任务

    Linux shell 操作 postgresql:删除间隔日期的数据-删除指定日期的数据-vacuumdb 清理数据库 -清理日志 -定期执行脚本 *修改pg_hba.conf 设置本地连接无密码, ...

  10. JS的一些常见验证代码

    1//檢查空串  2function isEmpty(str){  3 if((str == null)||(str.length == 0)) return (true);  4 else retu ...