标签:eve space def sdi mat ttl std lov tps
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e9
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
int x[11]={0,2,5,5,4,5,6,3,7,6};
int a[11],m,N;
const int MAXN=1e4+10;
int f[11][MAXN];
int n;
int dfs(int i,int j)
{
if(f[i][j]!=-1)
return f[i][j];
if(j==0)
return 1;
if(j<0)
return -inf;
f[i][j]=-inf;
for(int k=1;k<=m;++k)
{
if(j>=x[a[k]])
f[i][j]=max(f[i][j],1+dfs(i,j-x[a[k]]));
}
return f[i][j];
}
bool better(int i,int j,int k)
{
if(i-x[a[j]]<0)
return false;
if(!k)
return true;
if(f[a[j]][i-x[a[j]]]>f[a[k]][i-x[a[k]]])
return true;
if(f[a[j]][i-x[a[j]]]==f[a[k]][i-x[a[k]]] && a[j]>a[k])
return true;
return false;
}
int main()
{
n=read(),m=read();
memset(f,-1,sizeof f);
for(int i=1;i<=m;++i)
a[i]=read();
int i,j,k;
for(int i=1;i<=m;++i)
dfs(a[i],n-x[a[i]]);
for(i=n;i;)
{
k=0;
for(j=1;j<=m;++j)
if(better(i,j,k))
k=j;
i-=x[a[k]];
putchar(a[k]+'0');
}
return 0;
}
标签:eve space def sdi mat ttl std lov tps
原文地址:https://www.cnblogs.com/jklover/p/10390088.html