3265: 志愿者招募加强版

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 848  Solved: 436
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

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

Sample Output

14

HINT

题解:这一题类似于BZOJ1061,(几乎相同,只是把一段连续区间改为几段连续区间而已),做法一样,单纯形模板直接套就行;
具体看代码:
 
参考代码:
 #include<bits/stdc++.h>
using namespace std;
#define cls(x, val) memset(x,val,sizeof(x))
#define RI register int
#define eps 1e-6
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
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 N=;
const int M=;
int n,m;
double a[M][N],b[M],c[M],v;
inline void pivot(int l,int e)//矩阵的转秩
{
b[l]/=a[l][e];
for(int j=;j<=n;++j)
{
if(j!=e) a[l][j]/=a[l][e];
}
a[l][e]=/a[l][e];
for(int i=;i<=m;++i)
{
if(i!=l&&fabs(a[i][e])>)
{
b[i]-=a[i][e]*b[l];
for(int j=;j<=n;++j)
{
if(j!=e) a[i][j]-=a[i][e]*a[l][j];
}
a[i][e]=-a[i][e]*a[l][e];
}
}
v+=c[e]*b[l];
for(int j=;j<=n;++j)
{
if(j!=e) c[j]-=c[e]*a[l][j];
}
c[e]=-c[e]*a[l][e];
} inline double simplex()
{
while()
{
int e=,l=;
for(e=;e<=n;++e)
{
if(c[e]>eps) break;
}
if(e==n+) return v;
double mn=INF;
for(int i=;i<=m;++i)
{
if(a[i][e]>eps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i;
}
if(mn==INF) return INF;
pivot(l,e);
}
} int main()
{
n=read(),m=read();
for(RI i=;i<=n;++i) c[i]=read();
for(RI i=;i<=m;++i)
{
RI k=read();
while(k--)
{
int s,t;
s=read(),t=read();
for(RI j=s;j<=t;++j) a[i][j]=1.0;
}
b[i]=read();
}
printf("%d\n",(int)(simplex()+0.5));
return ;
}

最新文章

  1. MongoDB使用锦集
  2. Windows消息大全(转)
  3. 解决安装sql server 需要重启问题
  4. 元素设置position:fixed属性后IE下宽度无法100%延伸
  5. python staticmethod classmethod
  6. Tomcat绑定多个IP地址 多域名绑定
  7. 03_RHEL7.1去掉注册提示
  8. POJ 1740 A New Stone Game(多堆博弈找规律)
  9. 简单聊聊不可或缺的Nginx反向代理服务器--实现负载均衡【上篇】
  10. &lt;input&gt;内容居中、去框、不可编辑等
  11. 帆软报表(finereport)实现自动滚屏效果
  12. CodeForces - 589B(暴力+排序)
  13. 利用Python 脚本生成 .h5 文件 代码
  14. Codeforces 960F - Pathwalks
  15. AIO编程
  16. ceph状态信息靠谱查询
  17. ios日期格式转换
  18. docker 下 mysql 集群的搭建
  19. Parallel Programming AND Asynchronous Programming
  20. js函数柯里化

热门文章

  1. AI的真实感
  2. 深入理解计算机系统 第八章 异常控制流 part1
  3. tp5验证码的使用
  4. php如何在mysql里批量插入数据
  5. (C#)WPF:Property和Attribute的区别
  6. oracle实现&quot;limit&quot;功能
  7. Pashmak and Parmida&#39;s problem(树状数组)
  8. ACE框架 基于共享内存的进程间通讯
  9. Java IO入门
  10. SoapUI使用JDBC请求连接数据库及断言的使用