CL less used in the For loop
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; AtypedefLong Longll; - #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); the Const intmaxn= the; - intN,m,tt; - intdp[ the][1<< A],COST[MAXN],inch[MAXN][MAXN],A[MAXN][MAXN],ST[MAXN]; - intMain () + { - intI,j,k,ca=1; + #ifndef Online_judge AFreopen ("1.in","R", stdin); at #endif - while(SCANF ("%d%d", &n,&m)!=eof&&n&&m) - { - for(i=1; i<=m;i++) scanf ("%d", cost+i); - for(i=1; i<=n;i++) - for(j=1; j<=m;j++) scanf ("%d",&inch[i][j]); in for(i=1; i<=n;i++)//Escort - { to for(j=1; j<=n;j++) scanf ("%d",&a[i][j]); + } - //DP Initialization the for(i=1; i<=m;i++) * { $ for(j=0; J<= (1<<n)-1; j + +) dp[i][j]=-10000000;Panax Notoginseng } - for(i=0; I<= (1<<n)-1; i++) dp[0][i]=0; the for(i=1; i<=m;i++) + for(j=0; J<= (1<<n)-1; j + +) A { the inttot=0; + //the value obtained from the current state - inttemp=J; $ for(k=1; k<=n;k++) $ { -st[k]=temp%2; - if(St[k]) tot+= (inchK [i]-cost[i]); theTemp/=2; - }Wuyi //printf ("%d\n", tot); the //Company Bonus - for(k=1; k<=n;k++) Wu { - for(intkk=k+1; kk<=n;kk++) About { $ if(st[k]&&St[kk]) - { -tot+=A[K][KK]; - } A } + } the //the previous turn state - intans=1;//State sum $ intpre[1<< A]; thepre[0]=J; the for(k=1; k<=n;k++) the { the if(!st[k])//If the person is not present, it may or may not have occurred before - { in intsum=ans; the for(intkk=0; kk<ans;kk++) the { About intnst=pre[kk]^ (1<< (K-1)); thepre[sum++]=NST; the } theans=sum; + } - } the //plus the previous turn stateBayi intmax=-10000000; the for(k=0; k<ans;k++) the { - if(max<dp[i-1][pre[k]]) - { themax=dp[i-1][pre[k]]; the } the } thedp[i][j]=max+tot; - } the intmax=-10000000; the for(i=1; i<=m;i++) the {94 for(j=0; J<= (1<<n)-1; j + +) the { the if(Max<dp[i][j]) max=Dp[i][j]; the }98 } About if(max<=0) printf ("Stay home\n"); - Elseprintf"%d\n", Max);101 }102}
HDU 4049 2011 Beijing Online Tournament J-pressure DP * * *