Original link:
http://www.cnblogs.com/WTSRUVF/p/10800034.html
An entry form is desired pressure dp
dp[i][j]
The current state is i, for the case when j fractional number
then look at the code annotated
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <list> #include <cmath> #include <bitset> #define rap(i, a, n) for(int i=a; i<=n; i++) #define rep(i, a, n) for(int i=a; i<n; i++) #define lap(i, a, n) for(int i=n; i>=a; i--) #define lep(i, a, n) for(int i=n; i>a; i--) #define rd(a) scanf("%d", &a) #define rlld(a) scanf("%lld", &a) #define rc(a) scanf("%c", &a) #define rs(a) scanf("%s", a) #define rb(a) scanf("%lf", &a) #define rf(a) scanf("%f", &a) #define pd(a) printf("%d\n", a) #define plld(a) printf("%lld\n", a) #define pc(a) printf("%c\n", a) #define ps(a) printf("%s\n", a) #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #defineMEM (A, B) Memset (A, B, the sizeof (A)) #define _ :: ios_base sync_with_stdio (0), cin.tie (0) // The freopen ( "1.txt", "R & lt", stdin) ; the using namespace STD; const int MAXN = 110000 , INF = 0x7FFFFFFF ; int n-, m; int STR [ 13 is ] [ 13 is ]; int VIS [ 13 is ]; int F [ 15 ]; int DP [ . 1 << 12 is ] [ 550 ]; // current state of the case when the number is i, fraction J int GCD ( int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { f[0] = 1; for(int i = 1; i <= 12; i++) f[i] = f[i - 1] * i; int T; rd(T); while(T--) { mem(dp, 0); rd(n), rd(m); for(int i = 0; I <n-; I ++ ) { for ( int J = 0 ; J <n-; J ++ ) RD (STR [I] [J]); } int CNT = 0 ; DP [ 0 ] [ 0 ] = . 1 ; for ( int I = 0 ; I <( . 1 << n-); I ++) // traversing all states { CNT = 0 ; for ( int J = 0 ; J <n-; J ++) //Calculating a current has been selected before the number of IF (I & ( . 1 << J)) CNT ++ ; for ( int J = 0 ; J <n-; J ++) // Current cnt + 1 th position in which one should { IF (I & ( . 1 << J)) Continue ; for ( int K = 0 ; K <= m; K ++) // because we do not know the specific position of the first few so do not know the specific numerical values can iterate over all (m The maximum was 500) { IF (K + STR [CNT] [J]> = m) DP [I | ( . 1 << J)] [m] = + DP [I] [K]; the else DP [I | (1 << j)][k + str[cnt][j]] += dp[i][k]; } } } if(dp[(1 << n) - 1][m] == 0) printf("No solution\n"); else { int d = gcd(dp[(1 << n) - 1][m], f[n]); printf("%d/%d\n", f[n]/d, dp[(1 << n) - 1][m]/d); } } return 0; }
Reproduced in: https: //www.cnblogs.com/WTSRUVF/p/10800034.html