题目链接   (双层图, 一层维护工作,一层维护政策)

 #include <bits/stdc++.h>
using namespace std; inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int MAXN = ;
const int MAXM = ;
const int INF = 0x3f3f3f3f; struct Edge
{
int to, next, cap, flow, cost;
int x, y;
} edge[MAXM],HH[MAXN],MM[MAXN];
int head[MAXN],tol;
int pre[MAXN],dis[MAXN];
bool vis[MAXN];
int N, M;
char map[MAXN][MAXN];
void init()
{
N = MAXN;
tol = ;
memset(head, -, sizeof(head));
}
void addedge(int u, int v, int cap, int cost)//左端点,右端点,容量,花费
{
edge[tol]. to = v; edge[tol]. cap = cap; edge[tol]. cost = cost;
edge[tol]. flow = ; edge[tol]. next = head[u]; head[u] = tol++;
edge[tol]. to = u; edge[tol]. cap = ; edge[tol]. cost = -cost;
edge[tol]. flow = ; edge[tol]. next = head[v]; head[v] = tol++;
}
bool spfa(int s, int t)
{
queue<int>q;
for(int i = ; i < N; i++)
{
dis[i] = INF;
vis[i] = false;
pre[i] = -;
}
dis[s] = ;
vis[s] = true;
q.push(s);
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = false;
for(int i = head[u]; i != -; i = edge[i]. next)
{
int v = edge[i]. to;
if(edge[i]. cap > edge[i]. flow &&
dis[v] > dis[u] + edge[i]. cost )
{
dis[v] = dis[u] + edge[i]. cost;
pre[v] = i;
if(!vis[v])
{
vis[v] = true;
q.push(v);
}
}
}
}
if(pre[t] == -) return false;
else return true;
}
//返回的是最大流, cost存的是最小费用
int minCostMaxflow(int s, int t, int &cost)
{
int flow = ;
cost = ;
while(spfa(s,t))
{
int Min = INF;
for(int i = pre[t]; i != -; i = pre[edge[i^]. to])
{
if(Min > edge[i]. cap - edge[i]. flow)
Min = edge[i]. cap - edge[i]. flow;
}
for(int i = pre[t]; i != -; i = pre[edge[i^]. to])
{
edge[i]. flow += Min;
edge[i^]. flow -= Min;
cost += edge[i]. cost * Min;
}
flow += Min;
}
return flow;
}
const int inf = 1e9;
int P[],p,q,S[],T[];
void solve()
{
init();
int m,n,k,sum=;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",&P[i]),sum+=P[i];
scanf("%d%d%d",&m,&p,&q);
for(int i=;i<=m;i++)
scanf("%d%d",&S[i],&T[i]);
int st=,ed=;
for(int i=;i<=n;i++)
{
addedge(st,i,P[i],);
addedge(n+i,ed,P[i],);
}
addedge(st,n+,k,);
for(int i=p;i<=n;i++)
addedge(st,n+i,inf,q);
for(int i=;i<n;i++)
addedge(i,i+,inf,);
for(int i=;i<n;i++)
addedge(n+i,n+i+,inf,);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
if(i+T[j]<=n)
addedge(i,n+i+T[j],inf,S[j]);
}
int ans1=,ans2=;
ans1=minCostMaxflow(st,ed,ans2);
if(ans1==sum)printf("%d\n",ans2);
else printf("No solution\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
return ;
}

King's Pilots的更多相关文章

  1. HDU 5644 King's Pilots 费用流

    King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...

  2. HDU 5644 (费用流)

    Problem King's Pilots (HDU 5644) 题目大意 举办一次持续n天的飞行表演,第i天需要Pi个飞行员.共有m种休假计划,每个飞行员表演1次后,需要休假Si天,并提供Ti报酬来 ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  5. [bzoj1087][scoi2005]互不侵犯king

    题目大意 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上 左下右上右下八个方向上附近的各一个格子,共8个格子. 思路 首先,搜索可以放弃,因为这是一 ...

  6. King's Quest —— POJ1904(ZOJ2470)Tarjan缩点

    King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...

  7. 【状压DP】bzoj1087 互不侵犯king

    一.题目 Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上.下.左.右,以及左上.左下.右上.右下八个方向上附近的各一个格子,共8个格子. I ...

  8. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

  9. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout

    K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...

随机推荐

  1. Cocos2d-x中定时器的使用

    CCTimer:轻量级的计时器 CCTimer (void) ccTime  getInterval (void) void  setInterval (ccTime fInterval) bool  ...

  2. RQNOJ 188 购物问题:树形dp

    题目链接:https://www.rqnoj.cn/problem/188 题意: 商场以超低价格出售n个商品,购买第i个商品所节省的金额为w[i]. 为了防止亏本,有m对商品是不能同时买的.但保证商 ...

  3. Proftpd mysql认证配置文档

    Proftpd mysql认证配置文档 ver1.0, 2012/09/25 一.下载安装proftp mysql 下载 wget http://cloud.github.com/downloads/ ...

  4. Intellij IDEA 14代码错误提示如何调出来

  5. struts2的结果类型

    1.从struts-default.xml入手,得到结果类型列表以及对应的处理类: <result-types> <!-- 转发到action --> <result-t ...

  6. 通过在classpath自动扫描方式把组件纳入spring容器中管理。

    前面的例子我们都是使用xml的bean定义来配置组件,如果组件过多很臃肿.spring2.5引入了组件自动扫描机制,在指定目录下查找标注了@Component.@Service.@Controller ...

  7. 1026 Table Tennis (30)(30 分)

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  8. RabbitMQ的持久化机制

    一.问题的引出 RabbitMQ的一大特色是消息的可靠性,那么它是如何保证消息可靠性的呢?——消息持久化.为了保证RabbitMQ在退出,服务重启或者crash等异常情况下,也不会丢失消息,我们可以将 ...

  9. bzoj 3456 城市规划 —— 分治FFT / 多项式求逆 / 指数型生成函数(多项式求ln)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3456 首先考虑DP做法,正难则反,考虑所有情况减去不连通的情况: 而不连通的情况就是那个经典 ...

  10. poj1191棋盘分割——区间DP

    题目:http://poj.org/problem?id=1191 分析题意,可知每次要沿棋盘中的一条线把一块一分为二,取其中一块继续分割: σ最小经分析可知即为每块的xi和的平方最小: 故用区间DP ...