用dfs写,输出全0
查看原帖
用dfs写,输出全0
536337
eb0ycn楼主2023/12/23 11:30
#include <bits/stdc++.h>
using namespace std;
int n,m;
long long a[201],b[201],c[21][201],q,ans;
inline long long qpow(long long x,long long ret)
{
	if(!ret)return 1;
	long long p=qpow(x,ret>>1);
	return ret&1?p*p*x:p*p;
}
//tyzc 当前的所在的科目 sxyz 一共写了几个论文 now 这个科目写了多少篇  po 目前花了多少时间 
inline void dfs(int tyzc,int sxyz,int now,long long po)
{
	if(sxyz==n)
	{
		ans=min(ans,po);return ;
	}
	if(tyzc==m+1)return ;
	for(int i=0;i<=n-sxyz;++i)
	{
		dfs(tyzc+1,sxyz+i,i,po+c[tyzc][i]);
	}
	return ;
}
int main()
{
	//freopen("subject.in","r",stdin);
	//freopen("subject.out","w",stdout);
	ans=0xfffffffffffffff;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	{
		scanf("%lld%lld",a+i,b+i);
		for(int j=1;j<=n;++j)
		{
			c[i][j]=a[i]*qpow(j,b[i]);//预处理 
		}
	}
	dfs(0,0,0,0);
	printf("%lld",ans);
	return 0;
}
/*
10 3
1 2 
2 1
2 1
*/
2023/12/23 11:30
加载中...