标签:des style http color io os ar for strong
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #define maxn 50005 #define MAXN 200005 #define mod 1000000007 #define INF 0x3f3f3f3f #define eps 1e-6 const double pi=acos(-1.0); typedef long long ll; using namespace std; int n,w; int len[maxn],sum[maxn]; bool dp[maxn]; bool isok(int mid) { int i,j,last=0; memset(dp,0,sizeof(dp)); dp[0]=1; if(sum[n]+n-1<=w) return true ; for(i=0; i<n-1; i++) { if(!dp[i]) continue ; for(j=max(i+2,last+1); j<=n; j++) { if(w<sum[j]-sum[i]+j-i-1) break ; if(w>sum[j]-sum[i]+ll(j-i-1)*mid) continue ; last=j; dp[j]=1; if(sum[n]-sum[j]+n-j-1<=w) return true ; } } return false ; } void solve() { int i,j,le=1,ri=w,mid,ans; while(le<=ri) { mid=(le+ri)>>1; if(isok(mid)) { ans=mid; ri=mid-1; } else le=mid+1; } printf("%d\n",ans); } int main() { int i,j; while(~scanf("%d%d",&w,&n)) { if(w==0&&n==0) break ; sum[0]=0; for(i=1; i<=n; i++) { scanf("%d",&len[i]); sum[i]=sum[i-1]+len[i]; } solve(); } return 0; }
uva live 6190 Beautiful Spacing (二分+dp检验 根据特有性质优化)
标签:des style http color io os ar for strong
原文地址:http://blog.csdn.net/tobewhatyouwanttobe/article/details/39780085