来打个酱油 3.1是最小生成树模板
View Code
1 /* 2 ID: shangca 3 LANG: C++ 4 TASK: inflate 5 */ 6 #include <iostream> 7 #include<cstdio> 8 #include<cstring> 9 #include<algorithm> 10 #include<stdlib.h> 11 using namespace std; 12 int c[10010],w[10010],dp[10010]; 13 int main() 14 { 15 freopen("inflate.in","r",stdin); 16 freopen("inflate.out","w",stdout); 17 int i,j,k,n,m; 18 cin>>n>>m; 19 for(i = 1 ; i <= m ; i++) 20 cin>>w[i]>>c[i]; 21 dp[0] = 0; 22 for(i = 1; i <= n ; i++) 23 for(j = c[i] ; j <= n ; j++) 24 dp[j] = max(dp[j-c[i]]+w[i],dp[j]); 25 cout<<dp[n]<<endl; 26 return 0; 27 }