結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
![]() |
提出日時 | 2025-01-27 15:26:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,087 bytes |
コンパイル時間 | 2,209 ms |
コンパイル使用メモリ | 204,412 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-27 15:26:38 |
合計ジャッジ時間 | 3,091 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#include<bits/stdc++.h> #define int long long #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() using namespace std; template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;} template<typename T>ostream&operator<<(ostream&O,vector<T>&v){for(auto&i:v)O<<i<<' ';return O;} namespace AC{ struct node{ int x,y; string name; }; void solve(){ int n,m,k,p; cin>>n>>m>>k>>p; n++,m++; vector<node>v(k); for(auto&[x,y,s]:v)cin>>x>>y>>s; vector<int>ans; int mx=0; for(int b=0;b<1<<k;b++){ if(__builtin_popcount(b)!=p)continue; vector<int>tmp; vector<vector<int>>dp(n+1,vector<int>(m+1,0)); for(int i=0;i<k;i++)if((1<<i)&b)tmp.push_back(i); else dp[v[i].x][v[i].y]=-1; dp[0][0]=1; for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(dp[i][j]!=-1){ if(dp[i+1][j]!=-1)dp[i+1][j]+=dp[i][j]; if(dp[i][j+1]!=-1)dp[i][j+1]+=dp[i][j]; } if(dp[n-1][m-1]>mx){ mx=dp[n-1][m-1]; ans=tmp; } } cout<<mx%1000000007<<endl; for(auto i:ans)cout<<v[i].name<<endl; } } signed main(){ int t=1; //cin>>t; while(t--)AC::solve(); }