Categories
不学无术

ZOJ Problem Set – 1002

原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002
试水ZOJ的第一题,果然ACM的难度比PAT大一些,入门题目都那么长…
思路其实不难,弄个二维数组来搞,有点回溯的味道,刚巧最近看书看到了分而治之还要动态规划什么的
某一步的结果= max{当前位置放置1个+后面位置放置个数, 当前位置放置0个+后面位置放置个数}
然后就能做啦~
 

#include 
#include 
#include 
#include     // std::max
using namespace std;
enum state{
    READY, BLOCK, DISABLED, USED
};
/**
从i,j 开始找下一个可用的位置
**/
void findNextPossiblePos(int &i, int &j, int **inData, int N)
{
    for(int m=i; m=0; row--)
    {
        if(s1Data[row][j] == BLOCK)
            break;
        s1Data[row][j]= DISABLED;
    }
    //↓
    for(int row = i+1; row=0; col--)
    {
        if(s1Data[i][col] == BLOCK)
            break;
        s1Data[i][col] = DISABLED;
    }
    //→
    for(int col = j+1; cols2Result)? s1Result:s2Result;
    //mmax[i][j] = retVal;
    return retVal;
}
int main()
{
    int n;
    while(cin >> n)
    {
        if(n == 0)
            break;
        //create data
        int **data = new int*[n];
        for(int i=0; i> c;
                if(c == '.')
                    data[i][j] = READY;
                else if(c == 'X')
                    data[i][j] = BLOCK;
                else
                    data[i][j] = DISABLED;
            }
        }
        /////Start!
        int result = startJob(data, n, 0, 0);
        cout << result << endl;
    }
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.