北大ACM 1753怎么解

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/25 15:01:48
北大ACM 1753怎么解

北大ACM 1753怎么解
北大ACM 1753怎么解

北大ACM 1753怎么解
这个题目描述的是一个4*4的棋盘翻黑白棋的问题.算法上,不像动态规划,也不像递推,好像是一个数学类的题.
我的思路是从最终全黑或全白向其他情况转变,依次可能出现什么然后存在数组中.
解决这样的小数据4*4还是很easy,如果太大这样是不行.
做题少了,状态不佳,花了不少时间啊,下面C代码的AC了.
#include
#include
#define MAX_NUMBER\x050x010000 //count of unsigned short
#define UST unsigned short
UST SetNumber(UST num,UST type)
{
\x05const UST setData[16] = {
\x05\x050xc800,0xe400,0x7200,0x3100,
\x05\x050x8c80,0x4e40,0x2720,0x1310,
\x05\x050x08c8,0x04e4,0x0272,0x0131,
\x05\x050x008c,0x004e,0x0027,0x0013
\x05};
\x05return (num^setData[type]);
}
int main()
{
\x05int ret=-1;
\x05char *pflag = (char*)malloc(MAX_NUMBER*sizeof(char));
\x05UST *pNumBuf = (UST*)malloc(MAX_NUMBER*sizeof(UST));
\x05UST count[101]={0};
\x05UST maxnum,num,i,j;
\x05UST dstNum1,dstNum2;
\x05UST type = 0;
\x05int flag = 1;
\x05char in = 0;
\x05if (pflag && pNumBuf)
\x05{
\x05\x05memset(pflag,0,MAX_NUMBER*sizeof(char));
\x05\x05memset(pNumBuf,0,MAX_NUMBER*sizeof(UST));
\x05\x05count[1] = 1;
\x05\x05maxnum = 1;
\x05\x05while(flag && maxnum