ä¹ ãã¶ãã«é«é£æ度åé¡ã解ãã¦ã¿ãï¼
åé¡æ¦è¦
åãã¹ã®å¤ã 0 ã¾ã㯠1 ã§ãã ã°ãªãããèããã
ã°ãªãã ã®ãã¹ ããåºå®ããã¦ãããã¨ã¯ã次ã®æ¡ä»¶ãæºãããã¹ã¦ã® ã°ãªããã«ã¤ãã¦ããã¹ ã®å¤ãä¸æã«æ±ºã¾ããã¨ãããã
- ãã¹ã¦ã®è¡ã® 1 ã®åæ°ã ã¨çãã
- ãã¹ã¦ã®åã® 1 ã®åæ°ã ã¨çãã
次㮠åã®ã¯ã¨ãªã«çãããåã¯ã¨ãªã§ã¯æ´æ° ãä¸ããããã®ã§ãåãã¹ã®å¤ã 0 ã¾ã㯠1 ã§ãã ã°ãªããã§ãã£ã¦ãåºå®ããã¦ãããã¹ã®åæ°ãã¡ããã© åã§ãããããªãã®ãåå¨ãããã©ãããå¤å®ããã
å¶ç´
èãããã¨
ãã®æã®åé¡ã¯ã ã®å ´åãèãã¦ããã¨è¯ãã¨ãããã¨ã§ãã¾ãã¯å°ãã ãèãã¦ã¿ãããã®éç¨ã§åãã£ããã¨ã¯ã
ã°ãªããã®ãã¹ã¦ã®ãã¹ãåºå®ããã¦ããããã®å¿ è¦ååæ¡ä»¶ã¯ã次ã®æ¡ä»¶ãæºãã ãåå¨ããªããã¨ã§ãã
ãã®ãã¨ã示ãã¦ããçµå±ãåºå®ããã¦ãããã¹ã®åæ°ãã©ã®ããã«å¤ãããããããèããªãã¨ãããªãã®ã§ããã®åé¡ã解ã決å®æã«ã¯ãªããªãã£ãããããã§ã解æ³ã¸ã®èå¯ã«ã¤ãªãã£ãã
ä¸ã®ãã¨ã®è¨¼æã¯ãå¿ è¦æ§ã¯æããã§ããããã®ãã㪠ãåå¨ããã¨ã0, 1 ããã¹ã¦ flip ã§ãããã¨ãã示ãããååæ§ã®è¨¼æã¯å°ãé£ããã¦ãããã¹ã¦ã 0 ã§ããè¡ãåããããã¹ã¦ã 1 ã§ããè¡ãåãã®ãããããåå¨ãããã¨ã示ããã¨ãã§ãã¦ã帰ç´æ³ã«ãã£ã¦ç¤ºããã
ãªããä¸ã®äºæ³ã示ãããã«ãã°ãªãããäºé¨ã°ã©ãã§è¡¨ããã¨ãèãã¦ãããåã¯ãã®æ¹åã§ã¯èå¯ãé²ããããªãã£ãããå ¬å¼è§£èª¬ã§ã¯ã°ãªãããäºé¨ã°ã©ãã§è¡¨ãã¦èå¯ãã¦ããã
åºå®ããããã¹ã®åæ°
ä¸ã®ãã¨ã示ããã¨ãèªç¶ãªäºæ³ã¨ãã¦
åºå®ããã¦ããªããã¹ã¯ã縦ã横ã®é·ãããããã 2 以ä¸ã§ãããããªé·æ¹å½¢å½¢ç¶ï¼ããã§ã¯ãé£çµãã¦ããªããã®ãå«ããï¼ããªãã®ã§ã¯ãªããï¼
ã¨ãããã¨ã ã£ãï¼ç¸¦ã¾ãã¯æ¨ªã®é·ãã 1 ã ã¨éãï¼ãå®éã横ã®é·ãããããã 2 以ä¸ã§ãããããªé·æ¹å½¢ã«ã¤ãã¦ããã®é åããã¹ã¦åºå®ããã¦ããªãç¶æ ã«ãã¦ãæ®ããåºå®ããã¦ããç¶æ ã«ãããã¨ã¯å¯è½ã ï¼åºå®ããã¦ããªãã¨ããããã¹ã¦ 0 ã 1 ã«ããã°ããï¼ã
ããããããã ãã§ååã§ã¯ãªãã£ããåºå®ããã¦ããªãé·æ¹å½¢é åãè¤æ°åç¨æãããã¨ãã§ããããã ãããããã¯è¡æ¹åã«ãåæ¹åã«ãå ±æãã¦ã¯ãããªããå ±æããã¦ããã¨ãçµå±ãåºå®ããã¦ããªããã¹ãããã¼ã¸ãããããã«ãã¦ããã大ããªé·æ¹å½¢é åã«ãªã£ã¦ãã¾ããè¤æ°ã®é·æ¹å½¢é åããåºå®ããã¦ããªãç¶æ ã«ããããã«ã¯ããã¨ãã°ä¸ã®å³ã®ããã«ããã°ããï¼èµ¤æ ããåºå®ããã¦ããªããã¹ï¼ã
以ä¸ããã次ã®ããã«çµè«ã¥ããããã
ãã¹ã®éåããåºå®ããã¦ããªããã¹ã®éåãã¨ã§ããããã®å¿ è¦ååæ¡ä»¶ã¯ããããã®ãã¹ãé·æ¹å½¢å½¢ç¶ããªããã®ã®éã¾ãã§ãããã¾ããé·æ¹å½¢å½¢ç¶ãäºãã«è¡æ¹åã»åæ¹åã« disjoint ã§ãããã¨ã§ããã
ããã¾ã§ãããã°ããã¨ã¯ç°¡å㪠DP ã§è§£ããã
dp[i][j][s]
ï¼ ã°ãªããé åã«ããã¦ãåºå®ããã¦ããªããã¹ã®åæ°ãã¡ããã© åã§ãããã®ãåå¨ããã
è¨ç®é㯠ã¨ãªãã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; int main() { int N, Q, K; cin >> N >> Q; set<int> S; // åºå®ã§ããªããã¹ã®åæ°ã¨ãã¦ããããå¤ã®éå vector dp(N+1, vector(N+1, vector(N*N+1, 0))); dp[0][0][0] = 1; S.insert(0); for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { for (int s = 0; s <= N*N; s++) { if (!dp[i][j][s]) continue; S.insert(s); for (int ai = 2; i+ai <= N; ai++) { for (int aj = 2; j+aj <= N; aj++) { dp[i+ai][j+aj][s+ai*aj] = 1; } } } } } while (Q--) { cin >> K; if (S.count(N*N-K)) cout << "Yes" << endl; else cout << "No" << endl; } }