using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.GoalX = inpt[0]; this.GoalY = inpt[1]; int crystalCount = inpt[2]; int[] crystalRemain = new int[crystalCount]; this.CrystalList = new Crystal[crystalCount]; for (int i = 0; i < crystalCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CrystalList[i] = new Crystal(inpt[0], inpt[1]); crystalRemain[i] = inpt[2]; } long ans = GetAns(0, 0, crystalRemain); Console.WriteLine(ans); } private const long Mod = 1000000007; private Dictionary dic = new Dictionary(); private long GetAns(int x, int y, int[] remain) { if (remain.Sum() == 0) { if (x == GoalX && y == GoalY) { return 1; } else { return 0; } } long key = 0; for (int i = 0; i < remain.Length; i++) { key = key * 100; key += remain[i]; } if (dic.ContainsKey(key)) { return dic[key]; } long ans = 0; if (x == GoalX && y == GoalY) { ans = 1; } for (int i = 0; i < CrystalList.Length; i++) { if (remain[i] <= 0) { continue; } remain[i]--; ans += GetAns(x + CrystalList[i].MoveX, y + CrystalList[i].MoveY, remain); ans = ans % Mod; remain[i]++; } dic[key] = ans; return ans; } private int GoalX = 0; private int GoalY = 0; private Crystal[] CrystalList; private class Crystal { public int MoveX; public int MoveY; public Crystal(int x, int y) { this.MoveX = x; this.MoveY = y; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 1 0 3 -4 0 1 2 1 1 3 -1 1 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }