比赛 20241024 评测结果 AAAAA
题目名称 最佳课题选择 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.020 s
代码语言 C++ 内存使用 3.52 MiB
提交时间 2024-10-24 08:27:22
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 30;
const ll inf = 1e18;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}
void cmin(ll &x,ll y){x = min(x,y);}


int n,m;
ll a[N],b[N],f[N][210];

ll ksm(ll x,ll y){
	ll ans = 1;
	while(y){
		if(y & 1)ans = ans * x;
		x = x * x,y >>= 1;
	}return ans;
}
int main(){
	freopen("topic.in","r",stdin);
	freopen("topic.out","w",stdout);
	n = read(),m = read();
	for(int i = 1;i <= m;i++)a[i] = read(),b[i] = read();
	for(int i = 0;i <= m;i++)
		for(int j = 0;j <= n;j++)f[i][j] = inf;
	f[0][0] = 0;
	for(int i = 1;i <= m;i++){
		for(int j = 0;j <= n;j++){
			for(int k = 0;k <= j;k++)
				cmin(f[i][j],f[i-1][j-k] + a[i] * ksm((ll)k,b[i]));
		}
	}
	printf("%lld\n",f[m][n]);

	return 0;

}