Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure I get your solution idea, but I describe my AC solution:</p> <p>I'm using function with memorization, but you can re-write it using non-recurcive DP. </p> <p>Let's say we have our intervals in array </p> <p>pair a[100]; where a[i].first is interval begin and a[i].second is interval end.</p> <p>Sort this array by <em>begin</em> first (default behavior of stl sort algorithm with default pair comparator).</p> <p>Now imagine that we are 'putting' intervals one by one from beginning to end. </p> <p>let f(int x, int prev) return the number of ways to finish the filling if currently last interval is x and previous is 'prev'. </p> <p>we'll calculate it as follows:</p> <pre><code>int f(int x, int prev) { // if already calculated dp[x][prev], return it. Otherwise, calculate it if (dp[x][prev] != -1) { return dp[x][prev]; } if (a[x].second == m) { return dp[x][prev] = 1; // it means - X is last interval in day } else { dp[x][prev] = 0; for (int i = x + 1; i &lt; n; ++i) { // try to select next interval if (a[i].first &lt;= a[x].second &amp;&amp; // there must be not empty space after x interval a[i].second &gt; a[x].second &amp;&amp; // if this is false, the set won't be minimal - i interval is useless a[i].first &gt; a[x].first &amp;&amp; // if this is false, the set won't be minimal, x interval is useless a[prev].second &lt; a[i].first) { // if this is false, the set won't be minimal, x interval is useless. dp[x][prev] = (dp[x][prev] + f(i, x)) % 100000000; } } } return dp[x][prev]; } </code></pre> <p>After that we need to call this function for every pair of intervals, first of which start at 0 and second is connected with first:</p> <pre><code>for (int i = 0; i &lt; n; ++i) { if (a[i].first == 0) { for (int j = i + 1; j &lt; n; ++j) { if (a[j].first &gt; 0 &amp;&amp; // we don't need to start at 0 - in this case either i or j will be useless a[j].first &lt;= a[i].second &amp;&amp; // there must be no space after i interval a[j].second &gt; a[i].second) { // in opposite case j will be useless res = (res + f(j, i)) % 100000000; } } // also we need to check the case when we use only one interval: if (a[i].second == m) { res = (res + 1) % 100000000; } } } </code></pre> <p>After that we only need to print the res.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload