qinpengfei's blog

By qinpengfei, 16 years ago, In English
  • Vote: I like it
  • -3
  • Vote: I do not like it

By qinpengfei, 16 years ago, In English


who can help me ?
I use “maxflow and bsearch” to solve this problem ,but I get the wrong. I don't know where is worng in my code. I need you help me. Thank you very much.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By qinpengfei, 16 years ago, In English
please tell me why my code is wrong ? 
the first case gets the answer is 49, not 48... why ?
Thank you very much!

#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define MAXN 110

int f[MAXN][MAXN][MAXN];

int main()
{
    int i, j, k, n, k0;
    string s;
    cin >> s;
    n = s.size();
    memset(f, 0, sizeof(f));
    for (j = 0; j < 10; ++j)
    {
        for (i = 1; i < n; ++i)
        {
            f[j][i][i] = 1;
        }
    }

    for (k = 1; k < n; ++k)
    {
        for (i = 0; i + k < n; ++i)
        {
            j = i+k;
            printf("[%d %d]\n", i, j);
            if (j == i) continue;
            // [i, j]
            for (k0 = 0; k0 <= 9; ++k0)
            {
                int mm = (k0 + (s[i+1] - '0'));
                f[k0][i][j] += f[mm/2][i+1][j];
                if (0 != mm % 2)
                {
                    f[k0][i][j] += f[mm/2+1][i+1][j];
                }

            }
        }
    }
    int ans = 0;
    for (i = 0; i <= 9; ++i)
    {
       // cout << f[i][0][n-1] << endl;
        ans += f[i][0][n-1];
    }
    cout << ans << endl;
    return 0;
}



Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it