魔术棋子

棋盘形可行性dp

这种首先大力设状态:dp[i][j][k]代表考虑到 i,j;mod之后等于k是否可行,那么转移就很显然了,大力N^3转移就好了

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#define maxn 101
#define int long long
#define SZJ signed
#include<time.h>
#define AK main
#define half (l+r)>>1
#define SDOI () 
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i) 
#define dep(i,a,b) for (int i=a;i>=b;i--)  
#define erpe (i,a) for (int i=head[a];i!=-1;i=e[i].next)
bool dp[maxn][maxn][maxn];
int n,m,mx,num[maxn][maxn],ans; 
SZJ AK SDOI
{
	cin>>n>>m>>mx;
	rep(i,1,n) rep(j,1,m) cin>>num[i][j];
	dp[1][1][num[1][1]%mx]=1;
	rep (i,1,n) rep(j,1,m) rep(k,0,mx-1)
	{
		dp[i][j][k*num[i][j]%mx]|= dp[i-1][j][k];
		dp[i][j][k*num[i][j]%mx]|= dp[i][j-1][k];
	}
	queue<int>q;
	rep(i,0,mx) if (dp[n][m][i]) ans++,q.push(i);
	cout<<ans<<endl;
	while (!q.empty()) {cout<<q.front()<<" ";q.pop();}
}
posted @ 2018-11-05 14:54  Splitor  阅读(127)  评论(0编辑  收藏  举报