p1004Vijos

http://www.cnblogs.com/JerryZheng2005/articles/6685991.html

 1 #include<iostream>
 2 using namespace std;
 3
 4 int n,m,a[21],b[21];
 5 long long f[21][201];
 6
 7 long long mi(int x,int y)
 8 {
 9     long long t=1;
10     for (int i=0;i<y;i++) t*=x;
11     return t;
12 }
13
14 int main()
15 {
16     long long t;
17     int i,j,k;
18     cin>>n>>m;
19     for (i=1;i<=m;i++) cin>>a[i]>>b[i];
20     for (i=1;i<=n;i++) f[0][i]=0x7fffffff;
21     for (i=1;i<=m;i++)
22         for (j=1;j<=n;j++)
23         {
24             t=f[i-1][j];
25             for (k=1;k<=j;k++)
26                 t=min(t,f[i-1][j-k]+a[i]*mi(k,b[i]));
27             f[i][j]=t;
28         }
29     cout<<f[m][n]<<endl;
30     return 0;
31 }
时间: 2024-10-25 14:40:00

p1004Vijos的相关文章