jury compromise

Posted coder-cjh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jury compromise相关的知识,希望对你有一定的参考价值。

/*Code by Codercjh*/
/*time  unknown*/
/*status  unknown*/
/*problem unknown*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
    char c=getchar();T fh=0;bool f=false;
    while(!isdigit(c))f|=(c==-),c=getchar();
    while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
    x=f?-fh:fh;
    return;
}

int sump,sumd,cnt,ans[205],d[205][25][8005],a[205],b[205],f[25][8005],n,m,kase;
void print(int i,int j,int k){
    if(d[i][j][k])print(d[i][j][k]-1,j-1,k-(a[d[i][j][k]]-b[d[i][j][k]])),ans[++cnt]=d[i][j][k];
    else return;
}
int main(){
    read(n),read(m);
    while(n&&m){
        fr(i,1,n)read(a[i]),read(b[i]);
        memset(f,0xcf,sizeof(f));f[0][4000]=0;
        fr(i,1,n){
         fr(j,1,m)
          fr(k,0,8000)
           d[i][j][k]=d[i-1][j][k];
         rf(j,m,1)
          fr(k,4000,8000)
           if(!(k-(a[i]-b[i])<0||k-(a[i]-b[i])>8000)f[j][k]<f[j-1][k-(a[i]-b[i])]+a[i]+b[i]){
               f[j][k]=f[j-1][k-(a[i]-b[i])]+a[i]+b[i];
               d[i][j][k]=i;
           }
        }
         
        int ansi=1e9;
        fr(i,0,8000){
            if(abs(4000-i)<abs(4000-ansi))
             ansi=i;
            else 
             if(abs(4000-i)==abs(4000-ansi))
              if(f[m][i]>f[m][ansi])
               ansi=i;
        }
        sump=sumd=cnt=0;
        print(n,m,ansi);
        sort(ans+1,ans+cnt+1);
        fr(i,1,cnt)sump+=a[ans[i]],sumd+=b[ans[i]],cout<<ans[i]<<endl;
        printf("Jury #%d
Best jury has value %d for prosecution and value %d for defence:
",++kase,sump,sumd);
        fr(i,1,cnt-1)printf("%d ",ans[i]);printf("%d

",ans[cnt]);
        read(n),read(m);
    }
    return 0;
}

以上是关于jury compromise的主要内容,如果未能解决你的问题,请参考以下文章

jury compromise

POJ - 1015 Jury Compromise

Jury Compromise

[kuangbin 基础dp][POJ 1015] Jury Compromise(dp)

poj1015 Jury Compromise

[poj1015]Jury Compromise[DP]