func_code_string: #include <bits/stdc++.h>   using namespace std;   char ch[1005];   int dp[1005][3 * 1005];   int n, k;   int func(int idx, int diff) {     if (idx == n) {       return (abs(diff) == k);     }     if (abs(diff) == k) {       return 0;     }     int &re = dp[idx][diff + 1005];     if (re != -1) return re;     re = 0;     if (ch[idx] ==  W )       re = func(idx + 1, diff + 1);     else if (ch[idx] ==  L )       re = func(idx + 1, diff - 1);     else if (ch[idx] ==  D )       re = func(idx + 1, diff);     else {       re =           func(idx + 1, diff - 1) | func(idx + 1, diff) | func(idx + 1, diff + 1);     }     return re;   }   void path(int idx, int diff) {     if (idx == n) return;     if (ch[idx] ==  W ) {       printf( W );       path(idx + 1, diff + 1);     } else if (ch[idx] ==  L ) {       printf( L );       path(idx + 1, diff - 1);     } else if (ch[idx] ==  D ) {       printf( D );       path(idx + 1, diff);     } else {       if (func(idx + 1, diff + 1)) {         printf( W );         path(idx + 1, diff + 1);       } else if (func(idx + 1, diff)) {         printf( D );         path(idx + 1, diff);       } else {         printf( L );         path(idx + 1, diff - 1);       }     }   }   int main() {     scanf( %d%d%s , &n, &k, ch);     memset(dp, -1, sizeof dp);     if (func(0, 0)) {       path(0, 0);     } else       printf( NO n );     return 0;   }   