背包问题加强版orz
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; long long a[500][500],f[500],n,m,a1[500],b1[500]; int main() { cin>>n>>m; int i,j,k; for (i=1;i<=m;i++) cin>>a1[i]>>b1[i]; for (i=1;i<=m;i++) for (j=1;j<=n;j++) a[i][j]=a1[i]*pow(j,b1[i]); memset(f,127,sizeof(f)); f[0]=0; for (i=1;i<=m;i++) for (j=n;j>=1;j--) for (k=0;k<=n;k++) f[j]=min(f[j],f[j-k]+a[i][k]); cout<<f[n]; }