HDU 5807 Keep In Touch
加维降复杂度
#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的更多相关文章
- HDU 5807 Keep In Touch DP
Keep In Touch Problem Description There are n cities numbered with successive integers from 1 to n ...
- Hdu 5361 In Touch (dijkatrs+优先队列)
题目链接: Hdu 5361 In Touch 题目描述: 有n个传送机排成一排,编号从1到n,每个传送机都可以把自己位置的东西传送到距离自己[l, r]距离的位置,并且花费c,问从1号传送机到其他 ...
- HDU 5361 In Touch (2015 多校6 1009 最短路 + 区间更新)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:最短路.求源点到全部点的最短距离.但与普通最短路不同的是,给出的边是某点到区间[l,r]内随意 ...
- 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 ...
- 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 ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5514 Frogs 容斥定理
Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...
- HDU 5515 Game of Flying Circus 二分
Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
随机推荐
- UIPickerView 创建中国地区显示 省份 市
第一步初始化 UIPickerView *pickerview; //城市滚动表 NSDictionary *dict; //用于存储省份-城市的数据 NSArray *provinceArray; ...
- LeetCode #3. Longest Substring Without Repeating Characters C#
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- sql server 查询表基本信息sql
SELECT c.name,t.name TYPE,c.max_length,c.precision,c.scale,p.value FROM sys.systypes t INNER JOIN sy ...
- js中style的属性
下面这些属性都是通过js的style来设置css.只是整理了一部分,详细的可以参考相应的学习网站,不好的地方欢迎大家拍砖. alignContent :"" 属性在弹性容器内的各项 ...
- FreeMarker 语法
copy自http://demojava.iteye.com/blog/800204 以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主 ...
- C# lesson2
一.C#数据类型 1.值类型 包括数据相关(short.long.int .double.float).布尔(bool).枚举 2.引用类型 Object .对象.数组.字符串 二.存储方式 值类型 ...
- Vue.js 指南-基础
Installation 可以使用的方式: script标签方式加载vue.js cdn https://unpkg.com/vue@2.0.5/dist/vue.js npm Introductio ...
- JSON及与XML比较
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Decem ...
- Linux服务器时间设置命令
hwclock -r # 读取BIOS 时间 hwclock -w # 将当前系统时间写入BIOS date -s 2010/10/02 # 设置年月日 date -s 15: ...
- 关于odbc连接orcal,用户名密码大小写敏感问题
在oracle的之前版本时, 你的用户名密码是大小写不敏感的, 但在11g中, 数据库默认密码的大小写是敏感的, 于是我们就知道了一个事实, 那就是jdbc在给oracle密码时, 会将其变成大写,真 ...