ZOJ 3662
dp或者记忆化搜索#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define MC(a,b) memcpy(a,b,sizeof(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 1011;
const int maxc = 43;
const int maxk = 111;
const int mod = 1000000007;
int dp[maxn][maxc][maxk];
int n,m,t;
vector<int>a;
int g[maxc][maxc];
int mp[maxn];
i64 易做图(i64 _a, i64 _b)
{
if (!_a || !_b)
{
return max(_a, _b);
}
i64 _t;
while ((_t = _a % _b))
{
_a = _b;
_b = _t;
}
return _b;
}
int start()
{
a.clear();
for(int i=1;i<=m;i++)
{
if(m%i==0)
{
a.pb(i);
}
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<a.size();j++)
{
for(int k=0;k<=t;k++)
{
dp[i][j][k]=0;
}
}
}
MM(mp,-1);
for(int i=0;i<a.size();i++)
{
mp[a[i]]=i;
}
for(int i=0;i<a.size();i++)
{
for(int j=0;j<a.size();j++)
{
g[i][j]=a[i]*a[j]/易做图(a[i],a[j]);
g[i][j]=mp[g[i][j]];
}
}
dp[0][0][0]=1;
int x,y,z;
for(int u=0;u<=t-1;u++)
{
z = u+1;
for(int i=0;i<=n;i++)
{
for(int j=0;j<a.size();j++)
{
for(int k=0;k<a.size();k++)
{
y = g[j][k];
if(y!=-1)
{
x=i+a[k];
if(x<=n)
{
dp[x][y][z]+=dp[i][j][u];
dp[x][y][z]%=mod;
}
}
&nbs
补充:软件开发 , C++ ,