标签:style blog http color io os ar for div
1 //Accepted 2176 KB 47 ms 2 //杠杆平横的条件:sum(c[i]*sum(g[j]))=0 3 // 所有的hook到原点的距离乘它上面挂着的物体的重量和的和为0 4 //对于一个hook,它到原点距离与所挂重量的乘积能达到的最大和值为15*25*20 5 //设dp[i][j]为前i个hook挂上物品后达到的sum为j的方案数 6 //则dp[i][j]+=dp[i-1][j-c[i]*g[j]](1<=j<=n) 7 //前i个hook能达到j由前i-1个hook达到j-c[i]*g[j]加上第i个hook放上g[j]的重量得到 8 #include <cstdio> 9 #include <cstring> 10 #include <iostream> 11 #include <queue> 12 #include <cmath> 13 #include <algorithm> 14 using namespace std; 15 /** 16 * This is a documentation comment block 17 * 如果有一天你坚持不下去了,就想想你为什么走到这儿! 18 * @authr songt 19 */ 20 const int imax_n = 15*25*20; 21 int dp[25][imax_n*2+5]; 22 int c[25],g[30]; 23 int n,m; 24 void slove() 25 { 26 memset(dp,0,sizeof(dp)); 27 dp[0][imax_n]=1; 28 for (int i=1;i<=m;i++) 29 { 30 for (int j=1;j<=n;j++) 31 { 32 for (int k=0;k<=imax_n*2;k++) 33 { 34 int t=k+c[j]*g[i]; 35 if (t>=0 && t<=imax_n*2 && dp[i-1][k]!=0) 36 { 37 dp[i][t]+=dp[i-1][k]; 38 //printf("dp[%d][%d]=%d\n",i,t,dp[i][t]); 39 } 40 } 41 } 42 } 43 printf("%d\n",dp[m][imax_n]); 44 } 45 int main() 46 { 47 while (scanf("%d%d",&n,&m)!=EOF) 48 { 49 for (int i=1;i<=n;i++) 50 scanf("%d",&c[i]); 51 for (int i=1;i<=m;i++) 52 scanf("%d",&g[i]); 53 slove(); 54 } 55 return 0; 56 }
标签:style blog http color io os ar for div
原文地址:http://www.cnblogs.com/djingjing/p/3982194.html