加维降复杂度

#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. Java定时任务器

    java定时任务,每天定时执行任务.以下是这个例子的全部代码. public class TimerManager { //时间间隔 private static final long PERIOD_ ...

  2. 2px边框,4分之1内边框实现选中功能实现

    有时候我们要实现如下选中效果: 我给出一种解决办法: 首先选中的时候,加一个class(active),未选中的全部加一个class(inactive),外层给一个1px border,每个选项给一个 ...

  3. 一个挺好用的任务提示小软件 Rainlendar2

    Rainlendar2 可以把任务列出来放到桌面上.

  4. laravel利用subquery使左连接查询右表数据唯一查询

    如:表a,连接表b,b中有多条符合查询的记录 1.建立需要的子查询 $sub = DB::table('b')->select(['aid'])->selectRaw('max(id) a ...

  5. HDU2639[背包第K大]

    题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=2639] 题意:求第k大背包. 题解:利用二路归并的思想,求解第K大的值. #include<bi ...

  6. Python编程工具IDLE快捷键

    IDLE编辑器快捷键 自动补全代码        Alt+/(查找编辑器内已经写过的代码来补全) 补全提示              Ctrl+Shift+space(默认与输入法冲突,修改之) (方 ...

  7. __stack_chk_fail栈检查失败

    1. __stack_chk_fail的作用 在了函数的局部变量和保存的指令指针(译注:此处指返回地址和EBP)之间.这个值被称作金丝雀(“canary”)值 参考 http://www.freebu ...

  8. (十)foreac遍历、break和countinue以及标签和switch循环

    foreach语法,表示不必创建int变量去对由访问项构成的序列进行计数,foreach将自动产生每一项. 例:输出数组的所有元素. float f[]=new float[5]; f[0]=1.0f ...

  9. 使用MyBatis3时 selectOne 方法返回null的问题记录

    不多废话,直接上干货. mapper配置: <resultMap type="User" id="usermap"> <result colu ...

  10. BOS物流管理系统-第一天

    BOS物流管理系统-第一天-系统分析.环境搭建.前端框架 BoBo老师 整体项目内容目标: 对项目概述的一些理解 亮点技术的学习 注意学习方式:优先完成当天代码. 其他内容. 最终: 学到新的技术,会 ...