Question about bproblem I encountered when coding in c ++?

Revision en1, by wonderful_trip, 2021-05-09 06:54:13

I just made a mistake while participating in a coding contest in Vietnam and I came across a simple dp problem, the problem was: https://lqdoj.edu.vn/problem/dutpc2a : test of the contest organizers that I participated in https://atcoder.jp/contests/dp/submissions/me : The problem I encountered is the same as the one on atcoder

But I accepted this problem on atcoder but when I submitted the test from the contest organizer that I joined, I was wrong. And the problem I have is when I compare with the character '.' I got wrong but compare with '#' then accepted. Can someone explain to me why when I compare the character '.' wrong?

this my code wrong:

# include <bits/stdc++.h>

using namespace std;

# define nax (int) (1005)

const int mod = 1e9 + 7;

char v[nax][nax]; int dp[nax][nax]; int32_t main() { FASTIO

int n, m;

cin >> n >> m;

for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> v[i][j];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (i == 1 && j == 1)
{
dp[i][j]=1;
}
else
if (v[i][j] == '.')
{
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
}
}
}
cout << dp[n][m];
return 0;

}

and my code accepted:

# include <bits/stdc++.h>

using namespace std;

# define nax (int) (1005)

const int mod = 1e9 + 7;

char v[nax][nax]; int dp[nax][nax]; int32_t main() { FASTIO

int n, m;

cin >> n >> m;

for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> v[i][j];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (i == 1 && j == 1)
{
dp[i][j]=1;
}
else
{
if (v[i][j] != '#')
{
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
}
}
}
}
cout << dp[n][m];
return 0;

}

Thanks for the help and sorry for my english!

#### History

Revisions

Rev. Lang. By When Δ Comment
en6 wonderful_trip 2021-05-09 11:32:57 164
en5 wonderful_trip 2021-05-09 07:11:13 19 Tiny change: 'ntests/dp/submissions/me : The prob' -> 'ntests/dp/tasks/dp_h: The prob'
en4 wonderful_trip 2021-05-09 07:00:41 2
en3 wonderful_trip 2021-05-09 06:59:59 5
en2 wonderful_trip 2021-05-09 06:56:00 514
en1 wonderful_trip 2021-05-09 06:54:13 2463 Initial revision (published)