<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tongyu Lu</title>
    <description>The latest articles on DEV Community by Tongyu Lu (@stevenlu2004).</description>
    <link>https://dev.to/stevenlu2004</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F443575%2F8a233f85-63ca-4677-89c3-4220c191e338.png</url>
      <title>DEV Community: Tongyu Lu</title>
      <link>https://dev.to/stevenlu2004</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stevenlu2004"/>
    <language>en</language>
    <item>
      <title>High School Research #00 | Getting Started: idea + some literature review + glossary</title>
      <dc:creator>Tongyu Lu</dc:creator>
      <pubDate>Thu, 08 Oct 2020 05:17:54 +0000</pubDate>
      <link>https://dev.to/stevenlu2004/high-school-research-00-getting-started-idea-some-literature-review-glossary-1mbe</link>
      <guid>https://dev.to/stevenlu2004/high-school-research-00-getting-started-idea-some-literature-review-glossary-1mbe</guid>
      <description>&lt;p&gt;Part of a series: &lt;a href="https://dev.to/stevenlu2004/series/9143"&gt;High school research&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I want to do
&lt;/h2&gt;

&lt;p&gt;I don't really know. Or, I didn't. Either way, I am looking at something but I'm still not so sure yet.&lt;/p&gt;

&lt;p&gt;My current idea comes from some stuff I saw about detecting forgery in scientific publications by searching for duplicate images. After a bit of searching, I decided that for now, it'll just be "near-duplicate image detection", and I might come back to all the scientific publication forgery stuff later.&lt;/p&gt;

&lt;h2&gt;
  
  
  A bunch of previous literature &amp;amp; quick notes
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;All these are about detecting near-duplicate image forgery and image splicing. This is just a small part of it and definitely not all, but that's for today. I'm a bit too lazy to get this organized any better XD&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/abstract/document/7916155"&gt;https://ieeexplore.ieee.org/abstract/document/7916155&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2017; Conceptual model; deals with many different data types&lt;/li&gt;
&lt;li&gt;Not very useful for my purpose&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/abstract/document/4426397"&gt;https://ieeexplore.ieee.org/abstract/document/4426397&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2007; wavelets &amp;amp; log-polar mapping&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/7388368"&gt;https://ieeexplore.ieee.org/document/7388368&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2015; efficiency of DWT (Discrete Wavelet Transform)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/7546585"&gt;https://ieeexplore.ieee.org/document/7546585&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2016; RIC-LBP + Synthetic Aperture Radar; "outperforms some of the state-of-the-art methods"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://link.springer.com/article/10.1007%2Fs11277-020-07102-x"&gt;https://link.springer.com/article/10.1007%2Fs11277-020-07102-x&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2020; "Image and Video Forensics: A Critical Survey" &amp;lt;- Might be useful&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/5301325"&gt;https://ieeexplore.ieee.org/document/5301325&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2009; using SV features&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/5957431"&gt;https://ieeexplore.ieee.org/document/5957431&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2011; "Eclosion Forgeries" (what's that?); Curvelet Image Enhancement + Edge Detection ("Canny operators")&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/5946873"&gt;https://ieeexplore.ieee.org/document/5946873&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2011; same image search; color-dependent feature vectors + 1-D descriptors&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/7389169"&gt;https://ieeexplore.ieee.org/document/7389169&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2015; Survey on block-based copy-move image forgery detection &amp;lt;- Could be useful&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/5697444"&gt;https://ieeexplore.ieee.org/document/5697444&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2010; DWT + blocks + lexicographic sorting + phase correlation; robust &amp;amp; reduce time&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/6274631"&gt;https://ieeexplore.ieee.org/document/6274631&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2012; Radon Transformation + phase correlation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/7823199"&gt;https://ieeexplore.ieee.org/document/7823199&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2016; Color histogram and moments (pixel-level); effective on multiple copy-move forgery attacks&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;a href="https://ieeexplore.ieee.org/document/7049877"&gt;https://ieeexplore.ieee.org/document/7049877&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2015; Survey on image forgery detection techniques &amp;lt;- May be useful?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;I marked "useful" on the surveys because they're generally a faster way to get to know about the big picture.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Some helpful glossary
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;I haven't got time to look them up yet; I will, and I will maintain a separate collection of annotated glossary that is regularly updated.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DCT Discrete Cosine Transform&lt;/li&gt;
&lt;li&gt;PCA Principal Component Analysis&lt;/li&gt;
&lt;li&gt;AWGN Additive White Gaussian Noise&lt;/li&gt;
&lt;li&gt;Kd-tree&lt;/li&gt;
&lt;li&gt;DWT Discrete Wavelet Transform&lt;/li&gt;
&lt;li&gt;SVD Singular Value Decomposition&lt;/li&gt;
&lt;li&gt;LPFFT Log-Polar Fast Fourier Transform&lt;/li&gt;
&lt;li&gt;FMT Fourier Mellin Transform&lt;/li&gt;
&lt;li&gt;Bloom filters&lt;/li&gt;
&lt;li&gt;Zernike moments&lt;/li&gt;
&lt;li&gt;UWT Undecimated Wavelet Transform&lt;/li&gt;
&lt;li&gt;PCA EVD PCA Eigenvalue Decomposition&lt;/li&gt;
&lt;li&gt;Zigzag scan&lt;/li&gt;
&lt;li&gt;LBP Local Binary Patterns&lt;/li&gt;
&lt;li&gt;Gaussian filter&lt;/li&gt;
&lt;li&gt;Wiener filter&lt;/li&gt;
&lt;li&gt;MLBP Multiresolution LBP&lt;/li&gt;
&lt;li&gt;RANSAC Random Sample Consensus&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Last change: tweaks on URLs; add series link&lt;/p&gt;

</description>
    </item>
    <item>
      <title>USACO 2014 December Gold 1</title>
      <dc:creator>Tongyu Lu</dc:creator>
      <pubDate>Sun, 16 Aug 2020 09:27:22 +0000</pubDate>
      <link>https://dev.to/stevenlu2004/usaco-2014-december-gold-1-4d5d</link>
      <guid>https://dev.to/stevenlu2004/usaco-2014-december-gold-1-4d5d</guid>
      <description>&lt;p&gt;↓ USACO 2014 December Gold 1 Problem Statement | TL;DR&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z5V0U_hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1acxgmbgws95z7ve91hq.png" class="article-body-image-wrapper"&gt;&lt;img alt="USACO 2014 December Gold 1 Problem Statement" src="https://res.cloudinary.com/practicaldev/image/fetch/s--z5V0U_hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1acxgmbgws95z7ve91hq.png" id="problem-statement"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code attached at the bottom.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR problem statement
&lt;/h2&gt;

&lt;p&gt;N (2&amp;lt;=N&amp;lt;=20) cows each has a height, a weight, and a strength (the max weight it can support on its shoulders).&lt;/p&gt;

&lt;p&gt;You need to stack up a subset of these cows so that&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;each cow can support the weight on its shoulders&lt;/li&gt;
&lt;li&gt;the total height reaches a provided constant H (1&amp;lt;=H&amp;lt;=1e9)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Following that, maximize the additional weight that the cow stack can still support, and output that number. If impossible, print impossible.&lt;/p&gt;

&lt;p&gt;Computational resource limit: 1000ms, 128MB&lt;/p&gt;

&lt;p&gt;Back to full problem statement&lt;/p&gt;

&lt;h2&gt;
  
  
  Analysis
&lt;/h2&gt;

&lt;p&gt;N&amp;lt;=20 just gives you a sense of where this is going: to have some kind of optimized status value for each combination of cows, with the combination crammed down into 20 bits (because all combinations is also the independent presence/absence of all cows). We'll come back to this.&lt;/p&gt;

&lt;p&gt;The key is the equivalence of one cow to a one-cow stack of cows, and viewing a stack of cows as composed of non-overlapping substacks. These substacks can be considered immutable to the big stack, and therefore have their own height, weight, and strength.&lt;/p&gt;

&lt;p&gt;Of course, a stack is genuinely an array of cows. For a stack S, the height and weight are obvious, and the strength is the minimum of each cow's strength minus the weight above it.&lt;/p&gt;

&lt;p&gt;For a stack AB formed of stack A on top of B, the numbers are as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;height(AB) = height(A) + height(B)
weight(AB) = weight(A) + weight(B)
strength(AB) = min(strength(A), strength(B) - weight(A))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can see that order doesn't matter until you look at the strength. In fact, for a particular set of cows, their order on a single stack matters only to the strength. We will call a stack of a set of cows optimal to the set if the stack strength is high as it can get to.&lt;/p&gt;

&lt;p&gt;We join stacks to make bigger ones, and it's easy to see why we don't need to consider using suboptimal stacks as building blocks: the strength formula above tells us that an optimal stack won't do worse than a suboptimal one, and as far as joining stacks goes, we don't care about what actually make up the stacks save for that their sets don't overlap so no cows are used twice.&lt;/p&gt;

&lt;p&gt;So, if you go over all combinations of optimal length-N and length-M stacks for which their sets don't overlap, you will get all optimal length-(N+M) stacks. And for every stack of height&amp;gt;=H that we get, we can update the result value.&lt;/p&gt;

&lt;p&gt;I considered going from length 1 to 2 to 4 to 8 and so on, but found the number of stack-joining operations blowing up (each time about the square of the number of possible sets). What's wrong with this is that with each stack size, we actually trim off many suboptimal sets, but we skipped many of these steps when we jumped up the numbers.&lt;/p&gt;

&lt;p&gt;What I eventually did was just adding 1 cow at a time. This limits the number of loops to 2^20*20 which is approx. 2e7, snuggly fitting into the time limit.&lt;/p&gt;

&lt;p&gt;But how to store and look up the sets their optimal stack states? We cram the information of the presence of 20 cows into 20 bits, and there're just about 1e6 cow combinations possible. We could store a lot of data for each set this way, even more than we need.&lt;/p&gt;

&lt;p&gt;To traverse all n-cow sets before going to (n+1)-cow sets, we use a queue similar to what we do in BFS (because I can't think of an elegant iterative way), starting from an empty set (0), and for each queue front, we examine the set plus another from any of the unused cows and push to the queue as we see fit.&lt;/p&gt;

&lt;p&gt;Of course we could get this to run cleaner: obviously we can trim the unreachable sets. But another one not so obvious is that once the height gets to H, we update the max strength and throw away the set. Why? Well, if it's already height H, making the stack even higher is only going to decrease the strength.&lt;/p&gt;

&lt;p&gt;At this point I realize that I made a mistake that actually made the second optimization obsolete. When you see it, it should have been fixed, but the problematic code is below. Pause here and see if you can see what's wrong. Well? I stop the stack only when it updates the max strength, causing sets that don't work as well to pass. This lets through about half of these sets. Pretty bad, huh?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;H&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;maxs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// If height is reached and strength is better&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;maxs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;                   &lt;span class="c1"&gt;//     Update global valid max-strength&lt;/span&gt;
    &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                           &lt;span class="c1"&gt;//     Any more added cows will not increase strength&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two lines above that, checking whether the in-queue element is reachable, is also redundant, because if the element is unreachable it will not be in queue. I commented them out but you can still see them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my first post. I try to explain this problem as simply as possible. Please comment if you think I could have been more clear in some parts:)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Full source code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// guard.c&lt;/span&gt;
&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#define MAXN 20
#define MIN(a, b) ( (a &amp;lt; b) ? a : b )
#define MAX(a, b) ( (a &amp;gt; b) ? a : b )
#define INF64 0x7fffffffffffffff
&lt;/span&gt;
&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;ll&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;ll&lt;/span&gt; &lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;ll&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="n"&gt;ll&lt;/span&gt; &lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;dw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="n"&gt;ll&lt;/span&gt; &lt;span class="n"&gt;maxs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MAXN&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;FILE&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s_prime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"guard.in"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"r"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;fscanf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"%lld%lld"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;_0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;fscanf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"%lld%lld%lld"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;fclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;memset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;INF64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;qf&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                             &lt;span class="c1"&gt;// Loop through compressed combination states with binary digit sum&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// printf("ds[0x%x]=%lld\n", q[qf], ds[q[qf]]);                                                                                      // //     There. Debug print.&lt;/span&gt;
        &lt;span class="c1"&gt;// if (ds[q[qf]] &amp;lt; 0)                                                                                                                // //     If unreachable&lt;/span&gt;
        &lt;span class="c1"&gt;//     continue;                                                                                                                     // //         Ignore&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                                  &lt;span class="c1"&gt;//     If height is reached&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;maxs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                            &lt;span class="c1"&gt;//         If strength is better&lt;/span&gt;
                &lt;span class="n"&gt;maxs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;                                                                                                            &lt;span class="c1"&gt;//             Update global valid max-strength&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                                                                                        &lt;span class="c1"&gt;//         Any more added cows will not increase strength&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;_0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                           &lt;span class="c1"&gt;//     Loop through possible add-1's&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s_prime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="n"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;dw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;//         If added-one is unused AND strength is better&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;ds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s_prime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                                                                 &lt;span class="c1"&gt;//             Update strength, obviously&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;                                                                                                      &lt;span class="c1"&gt;//             If height-uncached (also weight-uncached and not-in-queue)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dh&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;                                                                                   &lt;span class="c1"&gt;//                 Cache height&lt;/span&gt;
                    &lt;span class="n"&gt;dw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;                                                                                   &lt;span class="c1"&gt;//                 Cache weight&lt;/span&gt;
                    &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;qf&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                                                                 &lt;span class="c1"&gt;//                 Push into queue&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"guard.out"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxs&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;fputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Mark is too tall&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"%lld&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;fclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>usaco</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
