éè²diff
ã¨ããå¶ç´ãããã«ãæªããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 1 ä»¥ä¸ 20 以ä¸ã®æ´æ°ãããªããé·ã ã®æ°å ãä¸ããããã ãã®æ°åã®é¨åå (é£ç¶ã§ãªãã¦ãã) ã§ãã£ã¦ãä»»æã®æ´æ°ã«ã¤ãã¦ããã®é¨ååã«å«ã¾ããåæ°ã 0 åã¾ã㯠2 åã§ãããã®ãèããã â¦
ã¡ãã£ã¨å·¥å¤«ãå¿ è¦ãªæã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã æ£æ´æ°å ã¨ãæ£ã®æ´æ° ãä¸ããããã æ°åã®åºéã§ãã£ã¦ãç·åã ã§å²ã£ãä½ãã¨ãåºéå ã«å«ã¾ããè¦ç´ ã®åæ°ã¨ãçãããã®ã®åæ°ãæ±ããã å¶ç´ èããã㨠çµæ§ããããããè½ã¡çãã¦æ¡ä»¶ãâ¦
å ´ããã«ã¼ããææã«å ¥ããªãæ¹ãè¯ãå ´åãããã®ããããï¼ ãã¨ãå±é¢ç¶æ ãæ°å¤æ å ±ã«ã¨ã³ã³ã¼ãããããè¿·ã£ããã©ãã¨ã³ã³ã¼ãããªãã¦ãéã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã¯ãããé«æ©åã¯æ´æ° ã®æ¸ããã æã®ã«ã¼ããæã£ã¦ãã¦ãéæ¨åã¯æ´æ° ã®â¦
å ¬å¼è§£èª¬ã®æ¹ãã·ã³ãã«ã ã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®é å ã¨ãæ´æ° ãä¸ããããã ã®é£ç¶ãã åã®è¦ç´ ãããªãåºéï¼ éãããï¼ãã©ã³ãã ã«é¸ã³ãããã«ãã®åºéãã©ã³ãã ã·ã£ããã«ããã æçµçãªé åã®è»¢åæ°ã®æå¾ å¤ã mod 998244353 ã§æ±â¦
é¢ç½ãã£ãï¼ï¼ å®é¨ã§æãã¤ãããããããªãããæ°ã¥ããã証æãããç³»ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å æã¨å¾æãç³åãã²ã¼ã ãããã2 åã®å±±ããã£ã¦ãæåããããç³ã åç©ã¾ãã¦ããã交äºã«æ¬¡ã®æä½ãããã 2 å以ä¸ã®ç³ãç©ã¾ãã¦ããå±±ã 1 ã¤é¸â¦
ãx 軸㨠y 軸ãç¬ç«ã«èãããããã¨ã主客転åã»å¯ä¸å解ãã®åããæï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 座æ¨å¹³é¢ä¸ã«ã æ¬ã®ç´ç· ã¨ã æ¬ã®ç´ç· ãããã ãããã®ç´ç·ã®ãã¡ 4 æ¬ãé¸ãã§ã§ããé·æ¹å½¢é å㯠åãããããããã®é¢ç©ã®ç·åã 1000000007 ã§å²â¦
ãå°ãããã¨ãããã«ãæªããã£ãã®ã§ãã°ã©ããå°ãããããã¨ãèããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ãè¾ºæ° ã®æåã°ã©ããããã 辺 () ã¯ãé ç¹ ããé ç¹ ãçµã¶ ( 㯠0 ã¨ãã) 辺 () ã¯ãé ç¹ ããé ç¹ ãçµã¶ ãã®ã°ã©ãä¸ã®ãé ç¹ 0 ãå§ç¹ã¨â¦
ã°ãªãããå¹ åºãããé»è²ãã¹ã®å¨è¾ºã§ããã3 x 3 å é¨ã«é»è²ãã¹ããããã¨ããç¶æ³ãçºçããªããã¨ãæ´»ç¨ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã°ãªããã®åãã¹ã¯ç½è²ã¾ãã¯é»è²ã§ããã åã®ãã¹ãé»è²ã§ããï¼åº§æ¨ãä¸ããããï¼ã ãã®ã°ãªããå é¨ã®å 3â¦
è³æºé ååé¡ãªã©ã¨ãå¼ã°ããã貪欲æ³ã使ããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ éå»ã«ããä¼¼ãé¡é¡ãåºé¡ãããã¨ãããã drken1215.hatenablog.com åé¡æ¦è¦ æ£ã®æ´æ°ãããªãé·ã ã®æ°å ããããé ç¹ ããã¤æ¨ããã¹ã¦èããã¨ãã®ã ã®æå°å¤ãæ±ãã ( ã¯é ç¹ â¦
maspy ããã®æ¬¡ã®ãã¤ã¼ãããã¹ã¦ï¼ï¼ F(cnt,sum) ã¨ããçµã¨å®æ°å ç®ä½ç¨ãé 延ã»ã°æ¨ã«ã®ãã¨ããã®ã¯ããç¥ããã¦ããã¨æãã¾ãããããã¯è¦ç´ ã«å¯¾ãã (0ä¹å, 1ä¹å) ã¨è§£éã§ãã¦ãçµ (0,1,...,k ä¹å) ãªã©ã«ä¸è¬åã§ãã¾ããä»åã¯è¦ç´ (x,y) ã«å¯¾â¦
åãã åãé¸ã¶è¨å®ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ°å¤ ãä¸ãããã (è² å¤ããããã)ã ãããã®æ´æ°ãã åé¸ãã§ç©ãã¨ã£ãå¤ã®æ大å¤ãã1000000007 ã§å²ã£ãä½ããæ±ããã å¶ç´ èããã㨠æ¬è³ªçã«ã次㮠2 ãã¿ã¼ã³ã«åãããã¨èãããâ¦
ãã®æã®ç´¯ç©åé«éåãå端ãããªãè¦æãªãã¨ãããã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã ãã®æ°åãããã¤ãã®åºéã«åå²ããæ¹æ³ã®ãã¡ã çªç®ã®åºéã«å«ã¾ããæ°åã®è¦ç´ ã®ç·åã ã§å²ãåãããããªãã®ã®åæ°ã 1000000007 ã§â¦
LIS ã®å¿ç¨åé¡ãLIS ãåãã£ã¦ããã°ããã® DP ã®éç¨ãä¿åãã¦ãããã¨ã§ããã®åé¡ã解ãããã¨ããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã å ã«ã¤ãã¦ãè¦ç´ ãå«ããããªæ°å ã® LIS ãåå¨ãããã©ãããå¤å®ããã (ãã«ããâ¦
ã®è¨ç®éã¾ã§ãªãæ¯è¼çããã§ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è¡ ããã£ã¦ãè¡ éã®è¡ãæ¥ã«ã¯ ã ãã®éè¡æããããã åã®å¸å ´ãããããè¡ ã§è¡ããã åããããã æåãç¡éã®ææéãæã£ã¦ãããããã¤ãã®å¸å ´ã«åå ãã (å ¨ãåå ããªãã¦ããã)â¦
ã³ã³ãã¹ãä¸ã«ã¯éããããªãã£ããæµç³ã«ç²ãã¦ãã¦é ãåããªãã£ã......ããã¯ã¡ã¢ä»£ããã«è¨ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ°å¤ ãç確çã§åºã¦ããã«ã¼ã¬ãããããã å æã¨å¾æã交äºã«ã«ã¼ã¬ãããåã ãã¹ã¦ã®æ´æ°å¤ãæã£ããçµäºã§ãã ãã§â¦
ãããå ¸åçãåãããªæè²çåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ äºæ¬¡å å¹³é¢ä¸ã« åã®ç¹ãé ç½®ããã¦ãã (åã座æ¨ã«è¤æ°åã®ç¹ãé ç½®ããããã¨ããã)ããããã®ç¹ã«å¯¾ãã¦ã以ä¸ã®æä½ã åã¾ã§è¡ããã åã®ç¹ã®ä¸ãã 1 åé¸ã¶ ãã®ç¹ãä¸ä¸å·¦å³ã®ãããâ¦
é 延ã»ã°æ¨ (åºéå ç® + åºé max åå¾) ãç¨ããå¹³é¢èµ°æ»ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ äºæ¬¡å å¹³é¢ä¸ã« åã®ç¹ããããç¹ ã®åº§æ¨ã¯ ã§ããã ãã® 2 次å å¹³é¢ä¸ã§ãµã¤ãºã ã®é·æ¹å½¢é å (å³è¾ºã¨ä¸è¾ºã¯å«ã¾ãªã) ãèªç±ã«åããã¦ããã¨ãããã®é·æ¹å½¢é åã«è¦â¦
å®ã¯ DP ã®æ·»åã®åãããç¯å²ã log ãªã¼ãã¼ã§ãããã¨ãè¦æãåé¡ãããé«åº¦ãªåé¡ã§ããã°ãã°è¦ãããèãæ¹ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ äºæ¬¡å å¹³é¢ä¸ã«ç¹ ããããç¹ ã®åº§æ¨ã¯ ã§ããã ä»ãç¹ 1 ã«ãã¦ãååã¨ãã¦ç¹ ãé ã«ééãã¦æçµçã«ç¹ ã«å°â¦
åã®åºéããããåºéãã¡ãç¨ãã¦ãæå°ã³ã¹ãã§ãã¹ã¦è¢«è¦ãããã¨ããåé¡ãDP ç¶æ ã®æã¡æ¹ã工夫ãããã¨ã§è¨ç®éãå°ãããããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®åºéããã£ã¦ãé·ãã ã§ãããããããã¹ã¦ã 2 種é¡ã®åºéã§è¢«è¦ãããã é·ãã ã§ãâ¦
ã»ã°æ¨ä¸ã§ DP ããåé¡ã¨ãã¦ã人çã§æåã«è§£ãã¹ãåé¡ã¨è¨ãããããããªãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®åºéããããååºé ã¯ã ã§éã¿ã¯ ã§ããã ãããã®åºéããããã¤ãé¸ã¶æ¹æ³ã®ãã¡ã å ¨ä½ã被è¦ãããã®ã«ã¤ãã¦ãæå°éã¿ãæ±ããã å¶ç´â¦
ã¨ã¦ãæè²çåé¡ï¼ï¼ è»æ¬ã®äºåæ¢ç´¢ã®ç¯ã«ãå¹³åå¤ã®æ大åãããããã©ãã¾ãã«ããï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ãè¾ºæ° ã® DAG ãä¸ãããããå辺 ã«ã¤ãã¦ã ã§ãããã¨ãä¿è¨¼ãããã å辺 ã«ã¯ãç¾ãã ã¨ãã³ã¹ã ãã¤ãã¦ããã é ç¹ 0 â¦
é 延è©ä¾¡ã»ã°ã¡ã³ãæ¨ã®ç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 0 㨠1 ã®ã¿ãããªãé·ã ã®æåå ãä¸ããããã次㮠2 種é¡ã®ã¯ã¨ãªã«çããã ã¯ã¨ãª (1 L R)ï¼æåå ã®åºé å ã«ãããã1 ãé£ç¶ããåºéã®é·ãã®æ大å¤ãçãã ã¯ã¨ãª (2 L R)ï¼æåå â¦
ãæ»ã DPãã¾ãã¯ãFPSãã§ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåãç®±ã¯ç©ºã§ããã以ä¸ã®æä½ã åè¡ããåæä½å¾ã«ããã¦ã以ä¸ã®å¤ãçããã ç®±ã«å ¥ã£ã¦ãããã¼ã«ãããã¤ãé¸ã¶æ¹æ³ã§ãã£ã¦ããã¼ã«ã«æ¸ãããæ°å¤ã®ç·åã ã¨ãªãæ¹æ³ã®åæ°ã 998244353 ã§â¦
ãã®åé¡ãããã«ã±ã«æºå®å ¨äºåæ¨ã®ã©ã¤ãã©ãªãæ¡å ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ã®æ ¹ä»ãæ¨ãä¸ãããããé ç¹çªå·ã¯ ã§ãããåé ç¹ (> 2) ã«ã¤ãã¦ã親é ç¹ã¯ ã§ããã ãã®æ ¹ä»ãæ¨ã«ããã¦ãé ç¹ ããã®è·é¢ã ã§ãããããªé ç¹ã®åæ°ãæ±â¦
ã¾ã 1 ã¤ãMST ç³»ã®åé¡ã®ã¹ããã¯ãå¢ãããã§ãå®è³ªçã«ã¯æ´æ°åé¡ã ã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ãè¾ºæ° ã®ã°ã©ããããããã®ã°ã©ãã«ä»¥ä¸ã®æä½ ãå®æ½ãããã¨ã§éã¿ä»ãç¡åã°ã©ããä½ãã ã«å¯¾ãã¦ãé ç¹ ã¨é ç¹ % ã®éã«ãéã¿ ã®è¾ºãå¼µâ¦
ããããã®è©°ããã®æéãããããµã³ãã«ãå¼±ãã®ã§ãæç´ã·ãã¥ã¬ã¼ã·ã§ã³è§£ãå®è£ ãã¦ãããã¨ã®ä¸è´ã確ãããããªã©ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ '1'ã'9' ã®ã¿ãããªãæåå ãä¸ããããããã®æååã«å¯¾ãã¦æååãè¿ãé¢æ° ãããã ã¯æ¬¡ã®æä½â¦
ã¿ãããªé£ç«æ¹ç¨å¼ã解ããçµé¨ãããã°ãæãã¤ãããããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ (ã¤ã³ã¿ã©ã¯ãã£ã) 0 㨠1 ã®ã¿ãããªããµã¤ãº ã®æ°å ãããããæªç¥ã§ãããããã¤ã質åãç¹°ãè¿ããã¨ã§ããã®æ°åãç¹å®ãããã æ大㧠åã¾ã§è³ªåãâ¦
ã»ã°æ¨ã¨ãå¿ è¦ãªãã¦ãæ¬å½ã«åç´ãªå®è£ ã§è§£ããã®é¢ç½ã åé¡ã¸ã®ãªã³ã¯ åé¡ å¶ç´ èããã㨠ã¾ãã¯ãçæå¯è½ã§ããããã®åãããããç¹å¾´ä»ããèãããã¨æã£ããæ°åã®çææé ããããã«ãå ¥ãåæ§é ããã¦ããã®ã§ãã«ãã³åãé£æ³ããã ã«ãã³â¦
æåãåãã¹ãã¿ã¹ã¯ã«è¦ç«ã¦ã¦ãã¿ã¹ã¯ã®ä¾åé¢ä¿ãèãã DAG ä¸ã§ DP ã§ããªãããªã©ã¨èãããã©ããã¾ããããªãã£ããæ®éã«ã°ãªãããå·¦ããèãã¦ãã DP ã§ããã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããããããåãã¹ã¯ãã§ã«ç½è² (æå '.') â¦
ã²ã¼ã æ¢ç´¢ + bit DPãããå®è£ éããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å æã¨å¾æã交äºã« ã®ã°ãªããã®åãã¹ç®ã« o ã x ãæ¸ãã¦ãããå æ㯠o ãæ¸ããå¾æ㯠x ãæ¸ãã æ¸ãçµãã£ãã¨ãã次ã®ããã«å¾ç¹ãè¨ç®ãã ããã³ ã«å¯¾ãã¦ã ãã¹ ã¨ãã¹ ãåãâ¦