ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1353. Миллиардная Функция Васи

Why this DP solution doesnt work?
Послано Dmitriy 11 окт 2016 14:17
I thought that this problem is so easy. After many tries to solve that I should say: that is not so easy and I cant solve it! Please, if you DP-master tell me where I'm wrong.

So, the state is dp[sum][length] += dp[sum - digit][length - 1], for each digit 0..9. The base is dp[1..9][1] = 1.

I've got WA#10:
My program for 10 output: 43756 (correct answer: 43749)

I can't find a little bug ;(
Re: Why this DP solution doesnt work?
Послано Dmitriy 11 окт 2016 14:18
[code]

    for s := 1; s <= S; s++ {
        for l := 2; l <= 9; l++ {
            for d := 0; d < 10 && s - d > 0; d++ {
                if dp[s - d][l - 1] == 0 {
                    continue
                }

                dp[s][l] += dp[s - d][l - 1]

                if d == 0 {
                    dp[s][l]++
                }
            }
        }
    }
[/code]
Re: Why this DP solution doesnt work?
Послано Dmitriy 16 окт 2016 09:20
Please anyone...
Re: Why this DP solution doesnt work?
Послано Egor 1 дек 2016 23:39
You don't need to store previous positions:

for (int position = 2; position <= 9; position++)
  for (int sum = 81; sum > 0; sum--)
    for (int digit = 1; digit <= 9; digit++) if (sum >= digit)
      ways[sum] += ways[sum - digit];
Re: Why this DP solution doesnt work?
Послано Manciu Ion 1 янв 2017 05:26
because you have to start l at one and eliminate continue and s - d >= 0
Re: Why this DP solution doesnt work?
Послано http://xoptutorials.com/index.php/category/timus/ 1 янв 2017 23:42
Re: Why this DP solution doesnt work?
Послано IlushaMax 4 апр 2017 01:08
Guys, what are you doing in New Year? Hahaha
Re: Why this DP solution doesnt work?
Послано Dmitriy 13 фев 2018 06:22
No. You are wrong here.
I've found my error, it was a dp base.

Thx for all.