問題の意味
多項式の所定の数は、ドメインへの正の整数のシーケンスのすべての値がソート処理に続いて、複製を可能にします。配列アイテムのNを求めます。
考え
明白なアイデアを比較。
kの値が比較的小さいので、それほど時間は無視評価それぞれに近似することができます。それではシミュレーションをすることができ、それぞれが現在の値の多項式で満たされ、小さなヒープルートを維持します。
時間の複雑さはある\(O(MK + NK)\)を。
コード
#include <bits/stdc++.h>
using namespace std;
namespace StandardIO {
template<typename T>inline void read (T &x) {
x=0;T 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*10+c-'0';
x*=f;
}
template<typename T>inline void write (T x) {
if (x<0) putchar('-'),x*=-1;
if (x>=10) write(x/10);
putchar(x%10+'0');
}
}
using namespace StandardIO;
namespace Project {
#define int long long
const int N=30003;
int n,m,k;
int a[N][10];
struct node {
int x,y,z;
node () {}
node (int _x,int _y,int _z) : x(_x),y(_y),z(_z) {}
};
struct cmp {
inline bool operator () (const node x,const node y) {
return x.x>y.x;
}
};
priority_queue<node,vector<node>,cmp> q;
inline int ksm (int base,int pow) {
int res=1;
while (pow) {
if (pow&1) res*=base;
base*=base,pow>>=1;
}
return res;
}
inline int next (int x,int t) {
int res=0,mm=1;
for (register int i=0; i<=k; ++i) {
res+=a[x][i]*mm,mm*=t;
}
return res;
}
inline void MAIN () {
read(n),read(m),read(k);
for (register int i=1; i<=m; ++i) {
for (register int j=0; j<=k; ++j) {
read(a[i][j]);
}
q.push(node(next(i,1),i,1));
}
while (--n) {
node now=q.top();q.pop(),q.push(node(next(now.y,now.z+1),now.y,now.z+1));
}
write(q.top().x);
}
#undef int
}
int main () {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
Project::MAIN();
}