8.9 Jizhong training Day9

T1 painters

Description

windy there are N pieces of wood that needs to be whitewashed.
Each plank is divided into M grid.
Each grid to be painted red or blue.
windy each painting, on a board can only select a contiguous lattice, and then coated with a color.
Each grid can only be whitewashed once.
If you can only paint T windy times, right up to him how much paint the grid?
If a grid is not paint or paint the wrong color, wrong even paint.

Input

The first line contains three integers, NMT.
Then there are N rows, each row of a string of length M, '0' represents red, '1' represents blue.

Output

Output An integer representing the number of grid up to the right of the paint.

Sample Input

3 6 3
111111
000000
001100

Sample Output

16

Hint

100% data satisfies 1 <= N, M <= 50; 0 <= T <= 2500.

Examination room ideas / positive solution 

A feeling is looked DP, then began frantically pushed state, and the like has elapsed after the launch of a half-hour (weak, weak).

Peruse problem, because wood is divided into n blocks, we can be processed separately each board. Through a series of tight projections bloggers, binding orientation and the like such as Japanese metaphysical , that can be set F [i] [j], each row represents the i-th to j-th paint optimal solution, ZX [i] [j ] represents the i-th row of whitewashed j times the optimal solution. So it can launch equation (see equation specific program).

Code

#include <cstdio> 
#include <CString> 
#include <algorithm>
 the using  namespace STD; 

int n-, m, T, ANS;
 int W [ 55 ] [ 55 ], F [ 55 ] [ 2525 ] / * F [I] [j] represents each of the i-th row to the j-th optimal solution of paint * / , ZX [ 55 ] [ 2525 ] / * the optimal solution to the i-th row of the j-th paint ZX [i] [j] represents * / ;
 char CH [ 55 ] [ 55 ]; 

int main () 
{ 
    Scanf ( " % D% D% D " , & n-, & m, & T);
    for(int i=1;i<=n;i++)
        scanf("%s",ch[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            w[i][j]=w[i][j-1]+ch[i][j]-'0';
    for(int l=1;l<=n;l++)
    {
        memset(f,0,sizeof(f));
        for(int i=1;i<=m;i++)
            for(int j=1;j<=min(m,t);j++)
                for(int k=1;k<=i;k++)
                    f[i][j]=max(f[i][j],f[k-1][j-1]+max(w[l][i]-w[l][k-1],i-(k-1)-(w[l][i]-w[l][k-1])));
        for(int i=1;i<=t;i++)
            for(int j=1;j<=min(i,m);j++)
                zx[l][i]=max(zx[l][i],zx[l-1][i-j]+f[m][j]);
    }
    for(int i=1;i<=t;i++)
        ans=max(ans,zx[n][i]);
    printf("%d",ans);
    return 0;
} 

T2 lost

Description

windy lost. In the drawing there
The N nodes have to FIG, Windy from node 0, node must arrive exactly at the time T N-1.
Now given the directed graph, you can tell how many different paths windy total it?
Note: windy can not stay in a node, and directed by a strict time edge for a given period of time.

Input

The first line contains two integers, NT.
Then there are N rows, each row of a string of length N.
The i-th row and j as '0' from node i to node j no edges.
'1' to '9' represents from node i to node j takes time.

Output

Output an integer number of possible paths, this number may be large, the output simply divide this number by the remainder of 2009.

Sample Input

2 2
11
00

Sample Output

1

Hint

100% data satisfies 2 <= N <= 10; 1 <= T <= 1000000000.

Examination room ideas

Poison ah, although the examination time did not play, but think it should be and then a bunch of pruning with SPFA such as the shortest path algorithm, the results of the test came out positive solutions found and read this not so much.

Correct

Triple for matrix multiplication using violence to count the number of programs, but how to deal with issues ranging from the right side of it? Observation data value range, only the right side is 0 to 9, the number of points n <= 10, we can split the point of violence, it split into the right side of a chain, then the subject is solved. However, because the first contact with matrix multiplication find several programs so changed a bit long (dish ah).

Code

#include<cstdio>
#include<algorithm>
#include<cstring>
#define Mod 2009
using namespace std;

int n,t;
char ch[202];
struct Pike
{
    int Map[202][202];
}a,ans;

Pike operator * (const Pike a,const Pike b)
{
    Pike c;
    memset(c.Map,0,sizeof(c.Map));
    for(int i=1;i<=n*9;i++)
        for(int j=1;j<=n*9;j++)
            for(int k=1;k<=n*9;k++)
                c.Map[i][j]=(c.Map[i][j]+a.Map[i][k]*b.Map[k][j]%Mod)%Mod;
    return c;
}

void Quick(Pike s,int t)
{
    while(t)
    {
        if(t&1)
            ans=ans*s;
        s=s*s;
        t>>=1;
    }
}

int main()
{
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=8;j++)
            a.Map[(i-1)*9+j][(i-1)*9+j+1]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",ch+1);
        for(int j=1;j<=n;j++)
            if(ch[j]>'0')
                a.Map[(i-1)*9+ch[j]-(int)'0'][9*(j-1)+1]=1;
    }
    for(int i=1;i<=n*9;i++)
        ans.Map[i][i]=1;
    Quick(a,t);
    printf("%d",ans.Map[1][(n-1)*9+1]);
    return 0;
}

T3 Game

Description

windy learned a game. For the N 1 to N digits, it has a unique and different numbers 1 to N corresponding thereto. Initially windy put numbers in order 1,2,3, ......, N written on paper in a row. Then write their corresponding numbers in the row below. And then in a new row below their corresponding numbers written on. So again, until the sequence becomes again 1,2,3, ......, N. Such as: Relationship 123,456 corresponding to 1-> 2 2-> 3 3-> 1 4-> 5 5-> 4 6-> 6 windy operates as follows


1 2 3 4 5 6


2 3 1 5 4 6


3 1 2 4 5 6


12 3 5 4 6


2 3 1 4 5 6


3 1 2 5 4 6


1 2 3 4 5 6


In this case, we have several rows 1 to N arranged in seven rows of the embodiment. Now windy I want to know, for all the possible correspondence between the number of possible rows.

Input

An integer, N.

Output

An integer number of possible rows.

Sample Input

3

Sample Output

3

Hint

100% data satisfies 1 <= N <= 1000.

Examination room ideas

I did not think, so no idea (confidently).

Correct

I think this is positive solutions metaphysics, solution to a problem I do not write very clear Luanche up.

answer:

Code

#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

LL n,sl,ans;
LL book[1010],zs[1010];
LL f[1010];

void Make_zs()
{
    for(LL i=2;i<=n;i++)
    {
        if(!book[i])
            zs[++sl]=i;
        for(LL j=i+i;j<=n;j+=i)
            book[j]=1;
    }
} 

int main()
{
    scanf("%lld",&n);
    Make_zs();
    f[0]=1;
    for(LL i=1;i<=sl;i++)
        for(LL j=n;j>=zs[i];j--)
            for(LL k=zs[i];k<=j;k*=zs[i])
                f[j]+=f[j-k];
    for(LL i=0;i<=n;i++)
        ans+=f[i];
    printf("%lld",ans);
    return 0;
}

T4windy number

Description

windy defines a number windy.
Without leading zeros and adjacent to at least the difference between two numbers is called a positive integer number windy.
windy want to know, between A and B, including A and B, total number of windy number?

Input

Two integers, AB.

Output

An integer that indicates how many number of A ~ B windy there.

Sample Input

1 10

Sample Output

9

Hint

100% data satisfies 1 <= A <= B <= 2000000000.
 

Examination room ideas / positive solution

Listen to others is the number of bits DP, but I will not ah! So I started messing around, the results are wrong.

Change after the test questions, find it really is a digital template title DP ah.

Code

#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;

LL a,b,suma,sumb;
LL wz[11];
LL f[11][11];  //f[i][j]表示长度位i且最高位为j的windy数 

LL Work(LL x)
{
    LL sum=0,g=x,sl=0;
    while(g/10!=0)
    {
        wz[++sl]=g%10;
        g/=10;
    }
    wz[sl+1]=g;
    for(int i=1;i<=sl;i++)
        for(int j=1;j<=9;j++)
            sum+=f[i][j];
    sl++;
    for(int i=1;i<g;i++)
        sum+=f[sl][i];
    for(int i=sl-1;i>=1;i--)
    {
        for(int j=0;j<wz[i];j++)
        {
            if(abs(wz[i+1]-j)>=2)
                sum+=f[i][j];
        }
        if(abs(wz[i+1]-wz[i])<2)
            break;
    }
    return sum;
}

int main()
{
    scanf("%lld%lld",&a,&b);
    for(int i=0;i<=9;i++)
        f[1][i]=1;
    for(int i=2;i<=10;i++)
        for(int j=0;j<=9;j++)
            for(int k=0;k<=9;k++)
                if(abs(k-j)>=2)
                    f[i][j]+=f[i-1][k];
    printf("%lld",Work(b+1)-Work(a));
    return 0;
}

to sum up

Today exam, three questions DP, a matrix multiplication problem, there are three questions which are difficult to provincial election, you want me to life ah! !

I feel like a code fast enough, IQ exam to zero.

 

Guess you like

Origin www.cnblogs.com/Thm-V/p/11329784.html