BZOJ3112 ZJOI2013 防守战线
【待填
Code:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <vector> #include <set> #include <map> #include <queue> #define ps system("pause") #define message printf("*\n") #define pb push_back #define X first #define Y second #define PII pair<int,int> #define rep(a,b,c) for(int a=b;a<=c;a++) #define per(a,b,c) for(int a=b;a>=c;a--) using namespace std; int n,m; int info[10010][10010]; int pb[10010]; void init(){ scanf("%d%d",&n,&m); rep(i,1,n) scanf("%d",&info[i][0]); rep(i,1,m){ int l,r,qk; scanf("%d%d%d",&l,&r,&qk); rep(j,l,r) info[j][i]=1; info[0][i]=qk; } } void pivot(int x,int ned){ pb[0]=1;pb[1]=0; rep(i,1,m) if (info[x][i]) pb[++pb[0]]=i; rep(i,0,n){ if (info[i][ned]==0 || i==x) continue; rep(j,1,pb[0]) if (pb[j]!=ned) info[i][pb[j]]-=info[i][ned]*info[x][pb[j]]; info[i][ned]=-info[i][ned]; } } void work(){ while (1){ int now=-1; rep(i,1,m) if (info[0][i]>0) {now=i;break;} if (now<0) return ; int mx=0x7fffffff,po; rep(i,1,n) if (info[i][now]>0 && info[i][0]<mx){ mx=info[i][0];po=i; } pivot(po,now); } } int main(){ init(); work(); printf("%d\n",-info[0][0]); }