小奇取石子

小奇取石子

题解

本题需要根据数据范围的不同来考虑。

对于第一个30%的数据,打个暴力即可。

对于第二个30%的数据,一看n\leq 20,就是状压dp,将每一堆石子压个状态就行了。

对于第三个40%的数据,打个朴素dp就行了,表示dp_{i}表示i个石子选择的最少堆数。

源码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long LL;
int n,m,k,a[205];
int dp[2505],ans,dp1[(1<<20)+5];
#define gc() getchar()
template<typename _T>
inline void read(_T &x)
{
    _T f=1;x=0;char s=gc();
    while(s>'
posted @ 2021-07-09 02:12  StaroForgin  阅读(14)  评论(0)    收藏  举报  来源