线性规划与费用流。http://www.cnblogs.com/iiyiyi/p/5616080.html。数组范围开错了!!!然后2.31-1=0x7fffffff!=0x7f7f7f7f. 开始以为是+Y[i]然后add(i,i+1,inf,0)一直调一直调。。。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define clr(x,c) memset(x,c,sizeof(x))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=1005;
const int maxn=10005;
const int inf=0x7f7f7f7f;
struct edge{
int to,cap,cost;edge *next,*rev;
};
edge es[maxn<<2],*pt=es,*head[nmax],*p[nmax];
void add(int u,int v,int d,int w){
pt->to=v;pt->cap=d;pt->cost=w;pt->next=head[u];head[u]=pt++;
pt->to=u;pt->cap=0;pt->cost=-w;pt->next=head[v];head[v]=pt++;
head[u]->rev=head[v];head[v]->rev=head[u];
}
queue<int>q;
int a[nmax],dis[nmax],ai[nmax],si[maxn],ti[maxn],ci[maxn];
bool inq[nmax];
int mincost(int s,int t){
int cost=0;
while(1){
clr(dis,0x7f);clr(inq,0);inq[s]=1;dis[s]=0;
a[s]=inf;q.push(s);
while(!q.empty()){
int x=q.front();q.pop();inq[x]=0;
qwq(x) if(o->cap>0&&dis[o->to]>dis[x]+o->cost){
int to=o->to;dis[to]=dis[x]+o->cost;
a[to]=min(a[x],o->cap);p[to]=o;
if(!inq[to]) q.push(to),inq[to]=1;
}
}
if(dis[t]==inf) break;
cost+=dis[t]*a[t];
int x=t;
while(x!=s) p[x]->cap-=a[t],p[x]->rev->cap+=a[t],x=p[x]->rev->to;
}
return cost;
}
int main(){
int n=read(),m=read(),u,v,d,s=0,t=n+2;
rep(i,1,n) ai[i]=read();
rep(i,1,m) si[i]=read(),ti[i]=read(),ci[i]=read();
rep(i,1,n+1) {
u=ai[i]-ai[i-1];
if(u>0) add(s,i,u,0);
else add(i,t,-u,0);
}
rep(i,1,m) add(si[i],ti[i]+1,inf,ci[i]);
rep(i,1,n) add(i+1,i,inf,0);
printf("%d\n",mincost(s,t));
return 0;
}

  

1061: [Noi2008]志愿者招募

Time Limit: 20 Sec  Memory Limit: 162 MB
Submit: 3683  Solved: 2255
[Submit][Status][Discuss]

Description

  申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管。布布刚上任就遇到了一个难
题:为即将启动的奥运新项目招募一批短期志愿者。经过估算,这个项目需要N 天才能完成,其中第i 天至少需要
Ai 个人。 布布通过了解得知,一共有M 类志愿者可以招募。其中第i 类可以从第Si 天工作到第Ti 天,招募费用
是每人Ci 元。新官上任三把火,为了出色地完成自己的工作,布布希望用尽量少的费用招募足够的志愿者,但这
并不是他的特长!于是布布找到了你,希望你帮他设计一种最优的招募方案。

Input

  第一行包含两个整数N, M,表示完成项目的天数和可以招募的志愿者的种类。 接下来的一行中包含N 个非负
整数,表示每天至少需要的志愿者人数。 接下来的M 行中每行包含三个整数Si, Ti, Ci,含义如上文所述。为了
方便起见,我们可以认为每类志愿者的数量都是无限多的。

Output

  仅包含一个整数,表示你所设计的最优方案的总费用。

Sample Input

3 3
2 3 4
1 2 2
2 3 5
3 3 2

Sample Output

14

HINT

1 ≤ N ≤ 1000,1 ≤ M ≤ 10000,题目中其他所涉及的数据均 不超过2^31-1。

Source

 

[Submit][Status][Discuss]

最新文章

  1. 【tomcat】不同域名解析到同一tomcat不同项目上
  2. SQL,Linq,Lambda之间的转换练习
  3. 优化mysql运行环境的方法
  4. js jQuery中文字符串比较
  5. Mongodb Manual阅读笔记:MongoDB教程
  6. MVC RadioButton
  7. 在linux上使用交换文件扩展交换空间
  8. WinStore控件之Button、HyperlinkButton、RadioButton、CheckBox、progressBar、ScrollViewer、Slider
  9. 浅谈Python时间模块
  10. Selenium2+python自动化13-Alert
  11. NDK(18)使用C++ STL
  12. windows 与fedora时间差
  13. Android新建项目手动添加Layout布局
  14. 【 VS 插件开发 】二、了解Vs插件结构
  15. 解决TortoiseGit 推送 拉取需要密码的问题
  16. 红黑树(red-black tree)实现记录
  17. Failed to load package MonoAndroidDesignerPackage
  18. SQLServer 里面的 DDL,DML,DCL,TCL(转)
  19. Tinyos 第三版Make系统
  20. Java 程序员容易犯的10个SQL错误

热门文章

  1. 淘宝IP地址库API接口(PHP)通过ip获取地址信息
  2. dapper 自定义数据库字段和代码中Model字段不一致时候的mapping方法
  3. Django设置
  4. ContextMenuStrip控件
  5. pl/sql插入报错
  6. IOS开发之表视图添加索引
  7. easyui使用时出现这个Uncaught TypeError: Cannot read property &#39;combo&#39; of undefined
  8. keystone命令与client接口学习
  9. Mac 使用phpMyAdmin
  10. HTTP协议返回代码含义